Exporting Data to Excel with PHP and MySQL

Here in this quick tutorial I will let you know how to export grid data into excel file. Export/Import is very common functionality for web development, some time we need to export all grid data into excel file that time we need below method to export data into excel file. It’s very easy and simple steps in PHP, we need to set header information to force browser to open download window.

You can also check other tutorial of Export Data with PHP,

Here we have sample result set from MySQL and want to export in excel file.

Step 1: Created sample MySQL data in key value pair as like below.

Step 2: PHP code to get options type and force to browser download file instead of display.

Above code use to get format type and tells that browser to download excel file.

Step 3: Define html layout for display data in table and button to fire export-to-csv action.

Step 4: Now we will use jQuery code to get click event.


export-to-excel with php and mysql
I hope its help you!.

Demo and Download source Code From Below Link

21 thoughts on “Exporting Data to Excel with PHP and MySQL

  1. Dear friend this is more like csv format, excel format contains many features like formatting ,auto calculations ..etc.
    You should use open source excel libraries for that.


  2. this code downloading full page
    i want to download particular array in excel. what can i do for that..kindluy help me

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.