[英]PHPExcel doesnt download xls
Saw many similar questions but nothing helped. 看到了许多类似的问题,但无济于事。 I use PHPExcel.
我使用PHPExcel。 I tried
我试过了
$filename = "report.xls";
header("Content-Type: application/vnd.ms-excel; charset=utf-8");
header("Content-Disposition: attachment; filename=".$filename);
header("Cache-Control: max-age=0");
header("Content-Type: application/octet-stream");
header("Content-Description: File Transfer");
header("Content-Transfer-Encoding: Binary");
$objWriter = PHPExcel_IOFactory::createWriter($pExcel, 'Excel5');
$objWriter->save("php://output");
and this 和这个
$filename = "report.xlsx";
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header("Content-Disposition: attachment; filename=\"".$filename."\"");
header("Cache-Control: max-age=0");
header("Content-Type: application/octet-stream");
header("Content-Description: File Transfer");
header("Content-Transfer-Encoding: Binary");
$objWriter = PHPExcel_IOFactory::createWriter($pExcel, 'Excel2007');
$objWriter->save("php://output");
But it shows in browser "PKoCjKG D X [Content_Types].xml MN 0 "" like this and doesnt force to download. 但是它会在浏览器中显示为“ PKoCjKG.D.X。[Content_Types].xml MN.0....”“,并且不会强制下载。
change filename to $filename, if you determine it before. 如果之前确定过,请将文件名更改为$ filename。 Example:
例:
require_once 'Classes/PHPExcel.php';
$objPHPExcel = new PHPExcel();
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename='.$filename);
header('Cache-Control: max-age=0');
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$objWriter->save('php://output');
It's work for me. 对我来说有用。
header("Content-Type: application/vnd.ms-excel; charset=UTF-8");
header("Content-Type: application/force-download");
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");
header("Content-Disposition: attachment; filename=output.xls");
Try to Replace 尝试更换
header("Content-Type: application/vnd.ms-excel; charset=utf-8");
With 用
header('Content-type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
I faced similar (Not exact) issue and fixed it from above mentioned code, Also I used it Here . 我遇到了类似(不确切)的问题,并通过上述代码修复了它,我也在这里使用了它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.