Saving to a variable

Topics: Developer Forum, User Forum
Feb 21, 2010 at 6:33 AM

I am trying to use the objWriters to save the output to a php variable (so it can be processed by the functions chunk_split and base64_encode (for the purposes of attaching it to an email).

What would be the best way to do this?

Developer
Mar 19, 2010 at 3:10 AM

Try this:

$excel = new PHPExcel();
...

$writer = PHPExcel_IOFactory::createWriter($excel, 'Excel2007');
ob_start();
$writer->save('php://output');
$str = ob_get_contents();
ob_end_clean();

// check that we have a string
var_dump($str);