【问题标题】:Trying to download xlsx 2007 file in Internet Explorer尝试在 Internet Explorer 中下载 xlsx 2007 文件
【发布时间】:2012-05-30 08:18:24
【问题描述】:

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

【问题讨论】:

标签: php excel-2007 phpexcel


【解决方案1】:

是的,如果您使用的是 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-found/

我希望这会有所帮助。

【讨论】:

    【解决方案2】:

    使用application/vnd.ms-excel 代替application/vnd.openxmlformats-officedocument.spreadsheetml.sheet 以实现向后兼容性。

    如果您有权修改网络服务器的 MIME 设置, 你需要添加 AddType application/vnd.openxmlformats .docx .pptx .xlsx AddType application/vnd.openxmlformats-officedocument.spreadsheetml.sheet .xlsx 到你的,例如 apache conf。

    之后,将您的文件名改为Monthly-Report-$month-$year.xlsx

    【讨论】:

    • application/vnd.ms-excel 用于 BIFF 格式的 xls 文件,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet 用于 OfficeOpenXML xlsx 文件......这与向后兼容性无关. OP 正在为他的文件使用正确的 Content-Type。你告诉他使用错误的类型是出于完全虚假的原因
    • 我知道类型错误,但这是一种解决方法,因为其中一个终端可能没有安装它。
    • 这与服务器 mime 类型设置无关,这与发送到浏览器的标头有关....这不是解决方法,只是错误
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-10
    • 1970-01-01
    • 2019-04-30
    • 2012-05-29
    • 1970-01-01
    • 2014-12-10
    相关资源
    最近更新 更多