[英]Trying to download xlsx 2007 file in Internet Explorer
xlsx文件未在IE中下載,但在Firefox中正常工作,我的代碼是
$objPHPExcel->setActiveSheetIndex(0);
// Redirect output to a client’s web browser (Excel2007)
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header("Content-Disposition: attachment;filename='Monthly-Report-$month-$year'");
header('Cache-Control: max-age=0');
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$objWriter->save('php://output');
//$objWriter->save(str_replace('.php', '.xlsx', __FILE__));
exit;
IE中顯示錯誤消息,因為Internet Explorer無法下載xlsx.php(這是我的php文件,其中寫入了代碼)Internet Explorer無法打開此站點
是的,如果您使用的是HTTPS,則Internet Explorer會出現問題。 在處理文件下載時,需要從響應中除去Pragma標頭。
在下載之前,請輸入以下代碼:
header("Pragma: ");
僅當您使用安全的http運行時,情況才會如此,如果不是這樣,請告訴我們。
您可能會在我的博客文章中找到更多說明,但當我在https上遇到同樣的問題時,我卻錯了,因為它非常適合IE上的http。
我希望這有幫助。
使用application/vnd.ms-excel
代替application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
以獲得向后兼容性。
如果您有權修改Web服務器的mime設置,則需要向您的服務器添加AddType application/vnd.openxmlformats .docx .pptx .xlsx
AddType application/vnd.openxmlformats-officedocument.spreadsheetml.sheet .xlsx
,apache conf。
然后,將文件名更改為Monthly-Report-$month-$year.xlsx
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.