繁体   English   中英

PHPExcel不下载xls

[英]PHPExcel doesnt download xls

看到了许多类似的问题,但无济于事。 我使用PHPExcel。 我试过了

$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");

和这个

$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");

但是它会在浏览器中显示为“ PKoCjKG.D.X。[Content_Types].xml MN.0....”“,并且不会强制下载。

如果之前确定过,请将文件名更改为$ filename。 例:

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');

对我来说有用。

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");

尝试更换

header("Content-Type: application/vnd.ms-excel; charset=utf-8");

header('Content-type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');

我遇到了类似(不确切)的问题,并通过上述代码修复了它,我也在这里使用了它。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM