Export HTML Table Data to Excel or CSV and Download using PHP & MySQL
Here in this tutorial quickly i am going to explain how to export grid data or HTML table data to excel file or CSV ( comma-seperated values). Export/Import is very common functionality for web development, some time we need to export all grid data into excel file or csv file for reporting purposes. In those cases we need below method to export data into excel file or csv file. it’s very easy and simple steps in PHP, we need to set header information to force browser to open download window.
Step 1: Sample array data or MYSQL data in key-value pair
$data = array(
'0' => array('Name'=> 'user1', 'Status' =>'complete', 'Priority'=>'Low', 'Salary'=>'001'),
'1' => array('Name'=> 'user2', 'Status' =>'inprogress', 'Priority'=>'Low', 'Salary'=>'111'),
'2' => array('Name'=> 'user3', 'Status' =>'hold', 'Priority'=>'Low', 'Salary'=>'333'),
'3' => array('Name'=> 'user4', 'Status' =>'pending', 'Priority'=>'Low', 'Salary'=>'444'),
'4' => array('Name'=> 'user5', 'Status' =>'pending', 'Priority'=>'Low', 'Salary'=>'777'),
'5' => array('Name'=> 'user6', 'Status' =>'pending', 'Priority'=>'Low', 'Salary'=>'777')
);
Step 2: PHP to code for post action and also setting up header information for Excel or CSV files
No Comments
Leave a comment Cancel