Welcome to WebmasterWorld Guest from

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Can PHP write Excel 2003/2007 file from data taken from database?



6:13 am on Apr 8, 2011 (gmt 0)

5+ Year Member

Hi all,
At my workstation we have a mysql database containing customers payment information. My boss has just asked me to write a PHP application that can get data from this database and point the business analysts to save or download query results from the database in an excel format, either Excel 2003 or 2007. I have never done this task before. Searching on the web i found a tutorial that says this could be possible using a PEAR package SpreadSheetExcelWriter but generating only Excel version 5 (version of 1993), which means this PEAR version cannot help me.

Has someone done this task in the past or just point me to a good tutorial?

Thank you for your time to help.


7:42 am on Apr 8, 2011 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member

Hi there dbarasuk,

*Hopefully* I am not breaking any forum rules with this link; but I think this will be useful to you, I was playing with this last year, and has been in my bookmarks list ever since!

Have a play! [the-art-of-web.com]

If your successful, let us know. I just tried this code, and it works for me in excel 2003;2007 so should be good.



1:07 pm on Apr 8, 2011 (gmt 0)

5+ Year Member

Dear Matthew1980,
thank you so much. The link you gave me contains code that works fine. However, if you remember the code, it has a series of php native functions that are throwing errors in the generated excel file, those are array_values() and implode(). This first one was saying that the first parameter is expected to be an array and a NULL value was passed to it. This was a simple warning because i saw the excel file generated from the database.
Is there any other way to format the headers (comming from the database table) to something more readable by humans, and not just the table columns?



5:12 am on Apr 15, 2011 (gmt 0)

5+ Year Member

you might try searching for php excell codeplex


9:48 pm on Apr 16, 2011 (gmt 0)

WebmasterWorld Senior Member henry0 is a WebmasterWorld Top Contributor of All Time 10+ Year Member

Can't you directly from MySQL save as a CSV
then you have it

Featured Threads

Hot Threads This Week

Hot Threads This Month