How to solve the problem of PHP7 exporting Excel report to ERR_EMPTY_RESPONSE
This article mainly explains "how to solve the problem of exporting PHP7 to Excel newspaper ERR_EMPTY_RESPONSE". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Next let the editor to take you to learn "PHP7 export Excel newspaper ERR_EMPTY_RESPONSE how to solve it"!
An error page is displayed when using the exported Excel. At this time, it is found that the uploaded Excel can read the data normally, but not when exporting.
The version of PHP I use here is 7.1. The PHPExcel version uses 1.8.1. Github address:
Https://github.com/PHPOffice/PHPExcel/tree/1.8.1 . You can see that the author has not updated for 3 years.
Copy all the Class contents in PHPExcel to the vendor directory of thinkphp. Rename to PHPExcel. That is, replace the old plug-in with this 1.8.1 version.
I won't say exactly how to write Excel and introduce plug-ins. Tell me about the writing of the code.
The problem actually focuses on the Excel output. (the following is the way to successfully export Excel, and the previous part of generating Excel is omitted.) define the header and output it directly.
$filename = "template file" .date ("YmdHis"). Rand (1000 9999); $filename = iconv ("utf-8", "gb2312", $filename); header ("Pragma: public"); header ("Expires: 0"); header ("Cache-Control:must-revalidate, post-check=0, pre-check=0"); header ("Content-Type:application/force-download"); header ("Content-Type:application/vnd.ms-execl"); header ("Content-Type:application/octet-stream") Header ("Content-Type:application/download");; header ('Content-Disposition:attachment;filename='.$filename.'.xls'); header ("Content-Transfer-Encoding:binary"); $objWriter- > save (' php://output')
You can also use PhpSpreadsheet to read and write Excel.
Github: https://github.com/PHPOffice/PhpSpreadsheet
Documentation: https://phpspreadsheet.readthedocs.io/en/develop/
At this point, I believe you have a deeper understanding of "how to solve the problem of PHP7 exporting Excel newspaper ERR_EMPTY_RESPONSE". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!