[英]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.