最新消息: 新版网站上线了!!!

PHPExcel在PHP7中无法导出的解决方法

在php7之前是可以正常导出的,在php7中使用save(‘php://output’)出现ERR_INVALID_RESPONSE的错误主要是下面错误导致。

1.header和缓冲区的错误导致,下面示例代码可以正常导出:

header('Content-type: application/vnd.ms-excel;charset=utf-8;name="' . $xlsTitle . '.xls"');
header("Content-Disposition: attachment; filename=$fileName.xls");
header('Cache-Control: max-age=0');
//header ('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
//header ('Cache-Control: cache, must-revalidate');
header ('Pragma: public');
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
$objWriter->save('php://output');

2.错误语法导致:打开PHPExcel\Calculation\Functions.php文件,删除掉581行的break即可。

转载请注明:谷谷点程序 » PHPExcel在PHP7中无法导出的解决方法