I found this great site that shows you how to export to Excel through PHP but it exports to the old .xls format. Does anyone know how to tweak this so that it exports to .xlsx instead?
http://www.phpsimple.net/tutorials/mysql_to_excel/
| SitePoint Sponsor |


I found this great site that shows you how to export to Excel through PHP but it exports to the old .xls format. Does anyone know how to tweak this so that it exports to .xlsx instead?
http://www.phpsimple.net/tutorials/mysql_to_excel/
Take a look at PHPExcel, does exactly what it say's on the tin.
Off Topic:
Pft, I'm so impressionable by marketing these days!![]()
@AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.





I hesitate because what I have works beautifully except for the fact that it doesn't export to xlsx.
In playing around with phpexcel I see that it saves a copy of an excel file to the same directory that the php file is in. How do I get it to display a 'save or open' window instead?



The sample test scripts do, but you're not obliged to.The argument for the object writer save method is a standard directory/filename
PHP Code:$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$objWriter->save('/usr/local/myWorkbooks/workbook1.xlsx');
PHP Code:// redirect output to client browser
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename="workbook1.xlsx"');
header('Cache-Control: max-age=0');
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$objWriter->save('php://output');


I don't think I ever got around to playing with the open/save dialog but I can't get the code above to work. I have placed it in the "01simple.php" so that it looks like this now
but I get a browser window with a bunch of (here are the two top lines)PHP Code:// Save Excel 2007 file
echo date('H:i:s') . " Write to Excel2007 format\n";
//$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
//$objWriter->save(str_replace('.php', '.xlsx', __FILE__));
// redirect output to client browser
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename="workbook1.xlsx"');
header('Cache-Control: max-age=0');
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$objWriter->save('php://output');
07:31:12 Create new PHPExcel object 07:31:12 Set properties 07:31:12 Add some data 07:31:12 Rename sheet 07:31:12 Write to Excel2007 format PK;< ![[Content_Types].xmlMN0=-Jܲ@%*Q`Icձ-{w{&I E j7"og%NKϦby]*yHFp4SH߸A\aXJD-dH


nevermind, I figured it out by looking at the "01 simple-download-xlsx.php" example file.
I use the code, and it runs ok. but the excel file download from website opened with some warning :
Excel found unreadable content in demo.xlsx. Do you want to recover the contents of this workbook? If you trust the source of the worksheet, click yes.
Can anyone help me?
Bookmarks