4

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 无法打开此站点

4

2 回答 2

3

是的,如果您使用的是 HTTPS,那么 Internet Explorer 会出现问题。在处理文件下载时,您需要从响应中删除 Pragma 标头。

下载前放以下代码:

header("Pragma: ");

仅当您使用安全 http 运行时才会出现这种情况,如果不是这种情况,请告诉我们。

您可能会在我的博客文章中找到更多描述,当我在 https 上遇到同样的问题时,我错了,而它在 IE 上非常适合 http。

http://blogs.digitss.com/programming/internet-explorer-was-not-able-to-open-this-internet-site-the-requested-site-is-either-unavailable-or-cannot-be-成立/

我希望这有帮助。

于 2012-05-30T09:01:45.900 回答
-1

使用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

于 2012-05-30T08:26:13.943 回答