Export Table Data to Excel Using PHP and Mysqli

This page is all about how to export table data to excel using PHP and mysqli. We have explained here step by step export data to excel in php. This functionality required for daily basis data backup for e-commerce or enterprise level website. This export functionality will help to manipulate a large amount of data after exporting to excel sheet. So if you are working in PHP based web application then it will easy to implementing this excel export functionality. If you want to fetch large amount data from database using mysqli then here that type of examples also given with source code with a demo.



Step-1

Index.php

In this page, we have to write a PHP and mysqli code to fetch and display data in table format.
Now in this index.php page, all data is populated which is ready for export. Then we need to add One export button. On click this button the page action would be data-export.php.

Step-2

export-data.php



In this page will have the same as index.php, means fetch and display data, then one more important code we have to put for export data to excel.

header(‘Content-Type: application/xls’);
header(‘Content-Disposition: attachment; filename=download.xls’);

This above two lines of code can perform as export to excel functionality.



Download source code

Click here to download the source code

Tags: , , , , , , , ,

Advertisements