Export to excel in php

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
r4r4
Forum Newbie
Posts: 11
Joined: Thu Jul 02, 2009 12:01 am

Export to excel in php

Post by r4r4 »

I am trying to export data from a mysql database to an excel spreadsheet using php. The script works fine in Excel 2003, but in 2007 I get the folowing error:

The file your are trying to open 'filename.xls', is in a different format that specified by the file extension. Verify that the file is not corrupted and is from a trusted srouce before opening the file. Do you want to open the file now?

You can still click "yes" and open the file. Anyone know a way to solve this annoyance?
Mark Baker
Forum Regular
Posts: 710
Joined: Thu Oct 30, 2008 6:24 pm

Re: Export to excel in php

Post by Mark Baker »

r4r4 wrote:I am trying to export data from a mysql database to an excel spreadsheet using php. The script works fine in Excel 2003, but in 2007
Anyone know a way to solve this annoyance?
Well to start with, how are you generating your Excel spreadsheet?
SeaJones
Forum Commoner
Posts: 48
Joined: Tue Jun 30, 2009 5:40 pm

Re: Export to excel in php

Post by SeaJones »

CSV is the simplest way, but PHPExcel is also a great tool for when you need a bit more flexibility as to how the sheet turns out. There are one or two other php Excel libraries out there, if you google them.
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: Export to excel in php

Post by califdon »

Split from another topic. Note to original poster: please ask new questions as a new post, don't "tail-gate" on another topic.
Post Reply