accessing ->save() data as a data stream?

Topics: Developer Forum
Dec 4, 2012 at 3:41 PM

I wondering if it is possbile to access the data created by phpexcel as a data stream, such as

$excel_data = $objWriter->save();

I realize I could write the data to a file and then read the file, but I am trying to avoid that step.

 
Dec 4, 2012 at 3:57 PM
If you do not want to write the file, so you want to send it directly to the browser?
If so, the save method accepts a particular parameter ' php://output' that does exactly this.
You can find a complete sample in Tests\01-simple-download - xlsx.php
Dec 4, 2012 at 7:58 PM

No, I'm trying to capture the data without sending it to the browser.

Coordinator
Dec 4, 2012 at 8:05 PM

Basic PHP (but not recommended because of the memory overheads)

$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
ob_start();
$objWriter->save('php://output');
$excelOutput = ob_get_clean();

though I can't really see a business case for it... what do you plan on doing with the content once you've got it in a PHP string variable?

Dec 5, 2012 at 7:28 PM

I have an application that sends out e-mails, including attachments. The source of attachment information is a variable in my code, which is then fed to my email function. I was hoping to add the ability to send an Excel attachment type if the user chose to do so. Thus my desire to capture the data in a php variable.