Export Data From PHP/MySQL to Microsoft Excel

Submitted by: 
Visitors have accessed this post 28520 times.

This code will help you on how to export data from mysql database using PHP to Microsoft Excel. The feature of this code is it export data from mysql to ms excel readable format. Download and try this code and if you have question, just leave comment and i will answer all your question.

database name: data

Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. After downloading it, you will need a program like Winzip to decompress it.

Virus note: All files are scanned once-a-day by SourceCodester.com for viruses, but new viruses come out every day, so no prevention program can catch 100% of them.


1. Re-scan downloaded files using your personal virus checker before using it.
2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.


its very useful but can you help me "2 or more data in one column in a row"just for other its a browser issue onclick="download();" is not working on some outdated browser like googletry mozilla..there it works for me.but not on google

what version do you use ?


How can i get output other than from 1-9 selection. I want to export my table data based on one column field information basis.
Need your Help.


its working for me....
Thanks for sharing...

gie, it doesnt print....

And how to apply styles? Please reply me...

Hey its not working.. Please reply

It is very useful...
how to insert excel data into php/mysql...

Hi, this not working on Chrome :( help me please

hello,i try to download this file and i tried to run them and i found this error"Notice: Undefined index: from in C:\xampp\htdocs\export\index.php on line 57

Notice: Undefined index: to in C:\xampp\htdocs\export\index.php on line 58"but are occur before entered item number.
- next i tried to use that print button and it doesn't work for exporting those data to the Microsoft excel.

download option is not working

Add new comment

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • You may insert videos with [video:URL]
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd> <table> <tr> <td> <th> <img> <h1> <h2> <h3> <iframe> [video]
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <asp>, <c>, <cpp>, <csharp>, <css>, <html4strict>, <java>, <javascript>, <mysql>, <php>, <python>, <sql>, <vb>, <vbnet>. The supported tag styles are: <foo>, [foo].
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.