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

前端 未结 2 1757
借酒劲吻你
借酒劲吻你 2020-12-14 16:09

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,

2条回答
  •  感动是毒
    2020-12-14 16:57

    Since PHPExcel writes the file to the disk in any case, if you capture stdout, what happens internally is that the file is written to the disk, then read from the disk (and deleted), printed to stdout and then captured in the output buffer.

    You might as well do:

    $tmpfile = tempnam($tmp_dir, 'phpxltmp');
    
    $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
    $objWriter->save($tmpfile);
    
    $excelOutput = file_get_contents($tmpfile);
    unlink($tmpfile);
    

提交回复
热议问题