PHP Excel输出

问题描述 投票:0回答:1

我必须使用phpexcel保存xlsx文件,但是它不起作用。它显示在浏览器控制台中,我可以将其保存在PC上。第一次使用。

$objPHPExcel = new PHPExcel();
$objPHPExcel->setActiveSheetIndex(0);
$objPHPExcel->getActiveSheet()->setTitle("title");
$objPHPExcel->getActiveSheet()->setCellValue('A1', 'Hi');
header('Content-type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment; filename="file.xlsx"');
header('Cache-Control: max-age=0');

$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$objWriter->save('php://output');
exit;

错误enter image description here

php console phpexcel writer
1个回答
0
投票

请看“ Serhat Akay”的回答,这全都与浏览器中的标头有关,它们如何理解与请求相关的内容。

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/octet-stream");
header("Content-Type: application/download");
header("Content-Disposition: attachment;filename=$filename");
header("Content-Transfer-Encoding: binary ");

$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$objWriter->save('php://output');

来源:How to choose location to save file excel with PHPExcel

© www.soinside.com 2019 - 2024. All rights reserved.