Question

Looking for a PHP solution to create Excel files on the fly (Think dynamic reporting).

Now I have seen PHP Excel and I know I can create a CSV file but are these by best options?

I running this script on a Linux system using PHP Excel but it doesn't set all the options

$objPHPExcel->getProperties()->setCreator("Phill");
$objPHPExcel->getProperties()->setLastModifiedBy("Phill");
$objPHPExcel->getProperties()->setTitle("Office 2007 XLSX Test Document");
$objPHPExcel->getProperties()->setSubject("Office 2007 XLSX Test Document");
$objPHPExcel->getProperties()->setDescription("Test document for Office 2007 XLSX");

Also if I give the extension .xls instead of the .xlsx it throws a invalid file and doesn't open. (NOTE: I'm using Open Office to view the generated excel sheet)

Wanted to know if there are any other/better solutions out there?

EDIT:

How I save the file

$file = '/path/to/777/dir/file.xlsx'; // not viewable by public
$objWriter = new PHPExcel_Writer_Excel2007($objPHPExcel);
$objWriter->save($file);
Was it helpful?

Solution

There are alternatives to PHPExcel, as listed here

But before you dismiss PHPExcel out of hand, I'd like to know why it isn't working. This is something that normally works without any problems; but your code snippet doesn't show anything about saving the file. How are you saving the file: which writer are you using?

$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
$objWriter->save('/path/to/777/dir/file.xls');

EDIT

or

$file = '/path/to/777/dir/file.xls'; // not viewable by public 
$objWriter = new PHPExcel_Writer_Excel5($objPHPExcel); 
$objWriter->save($file); 

The latest version of Open Office will (I believe) read .xlsx files as well, but it does prefer if they have the correct extension.

Note that the Excel5 Writer doesn't support document properties (though Excel2007 does). There is an active work item for this on the PHPExcel issues list.

OTHER TIPS

Yes there is. You can use Pear's Spreadsheet_Excel_Writer. It only creates BIFF8 or older files (Word 2003), but it works quite well.

Edit: I just noticed they are saying it needs a complete rewrite and don't recommend using it for new development. I've been using it for about 3 years in production systems, and other than a few tiny little bugs it's worked great for me...

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top