PHP export to xlsx?

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. :wink:

Off Topic:

Pft, I’m so impressionable by marketing these days! :lol:

Beaten to it by over half an hour, I’m slipping… put it down to my rewriting of the PHPExcel calculation engine taking a lot more of my time these days.
I’m not sure it can be called marketing if it’s a FOSS library can it?

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


$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$objWriter->save('/usr/local/myWorkbooks/workbook1.xlsx');


// 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

// Save Excel 2007 file
echo date('H:i:s') . " Write to Excel2007 format\
";
//$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');

but I get a browser window with a bunch of (here are the two top lines)

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].xml­”MNÃ0…÷=…å-Jܲ@%í‚Â*Q`ìIcÕ±-{úw{&I ˆE j7±"û½oüg÷œ%”NKë”ü‰Ï¦£by‰]*y„Hª†F¦Üap4SùØH¤ß¸Aªµ\¸ï„òÁa†­aŸŽXñJD£-dÄÙHì­

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?