运行以下代码后,我在未打印的浏览器 PDF 输出中也看不到任何 PDF 下载。显示空白页。
require_once 'Classes/PHPExcel/IOFactory.php';
$objPHPExcel = new PHPExcel();
$objPHPExcel->getActiveSheet()->setCellValue('c9','40');
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'PDF');
//You need to include and print to PDF the entire worksheets contained in the workbook
$objWriter->writeAllSheets();
//You need to assign a filename to the PDF file (write.pdf for example)
header('Content-type:Application/pdf');
header('Content-Disposition: attachment;filename="export.pdf"');
$objWriter->save('php://output');
代码上仍然有一个小错误。在浏览器中查看 PDF 时无法下载。请找到随附的屏幕截图。
最后上面的代码片段解决了这个问题