Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I write my excel spreadsheet into a variable, using PhpExcel?

Tags:

phpexcel

After loading a PHPExcel object with my data, I want to output the contents directly into a php variable, instead of writing to a file. Have I missed the method to do that, for it seems that the only way to save is to save to disk.

like image 383
Aaron Avatar asked Feb 27 '12 17:02

Aaron


People also ask

How write data from Excel to PHP?

You may use the following code: header('Content-Type: application/vnd. ms-excel'); header('Content-Disposition: attachment;filename="file. xlsx"'); header('Cache-Control: max-age=0'); $writer->save('php://output');

How do I merge cells in Excel using PHPExcel?

You can also use: $objPHPExcel->setActiveSheetIndex(0)->mergeCells('A1:C1'); That should do the trick.


1 Answers

You can use a writer to save to disk, or save to php://output. If the latter, you could use output buffering to capture that output and then store in a variable.... not sure quite why you'd want to do this though.

$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007'); ob_start(); $objWriter->save('php://output'); $excelOutput = ob_get_clean(); 
like image 183
Mark Baker Avatar answered Oct 19 '22 15:10

Mark Baker