Save export to server?

Feb 17, 2010 at 5:57 PM

I'm trying to use PHPExcel to generate an XLS file that will be saved to the server and then emailed to specific recipients. I am not sure how to get the file to save to the server rather than be downloaded by the user, can I please get some help with this?


Feb 17, 2010 at 9:07 PM

Simply pass a filename to the save() method of the appropriate writer. This should be a filename on the server.

$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');

Most of the examples in the /Tests directory do just this

Feb 18, 2010 at 2:36 AM

Awesome! Flexible enough to use a switch/case to either save to the server or send it to the browser.

One more question... I'm creating two sheets within my script. The first thing I do is create a new sheet object and title it. The problem is that the resulting workbook contains three sheets, one of them titled 'Worksheet'. So, instead of using:


$objML = $objPHPExcel->createSheet();
$objML->setTitle("Material List");

What should I be doing to start with the default sheet and rename it to "Material List"?


Feb 18, 2010 at 8:49 AM

Instantiating a PHPExcel object automatically creates a worksheet as well; so simply rename that one as your first sheet, and create a single, second sheet

$objPHPExcel = new PHPExcel();
$objML = $objPHPExcel->getActiveSheet();
$objML->setTitle("Material List");
Feb 18, 2010 at 2:56 PM

Thanks so much, Mark. You guys are very helpful and this class is an absolute lifesaver!