Writing PHPexcel to a buffer

The standard way to export an excel spreadsheet with PHPExcel is to have it written to disk, then extract that data using file_get_content(). But I am using symfony and wanted to be able to pass it around from a widget to a controller that would send it out with the appropriate headers. I didn't want to write to disk because it was a high volume application that would result in a lot of disk writes, and possible race conditions, if done poorly. Which is how I typically do things.

Not sure how to do it, I put a question up on stack overflow. I only got one answer, but it was the right answer, and I'm able to make PHPExcel write the contents of an excel file directly into a variable:

$writer = PHPExcel_IOFactory::createWriter($phpExcelObj, 'Excel2007');
   $excelOutput = ob_get_clean();

However, the guy that replied also made a snooty remark about how I was perhaps an idiot for not writing to disk first. I wrote a response saying that, while I appreciated his insights into my intellect, my question was how to do something, not his by-the-gospel opinion on whether or not I should follow the PHPExcel playbook.

Just before sending it, however, I started to wonder why he would say something like that, and whether or not he was just some crank trolling StackOverflow, so I checked out his profile.

Turns out he's one of the actual authors of PHPExcel. And rather well respected. I have 49 reputation points on Stack Overflow. He has 36,000. His opinion carries a bit more weight, I should think.

I sent him a note thanking him for his input, and then I voted him up.

1 comment: