PHPExcel输出到浏览器在IE中不起作用 [英] PHPExcel output to browser doesn't work in IE

查看:168
本文介绍了PHPExcel输出到浏览器在IE中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个PHP脚本,它使用PHPExcel打开模板,从数据库查询中插入值,然后将结果返回给浏览器。它在Firefox中完美运行,但在Internet Explorer(8)中,当它试图打开文件时,它会断开:

I have a PHP script that uses PHPExcel to open a template, insert values from a database query then return the result to the browser. It works perfectly in Firefox, but in Internet Explorer (8), when it attempts to open the file, it breaks with:


Internet Explorer无法从my.domain下载generate.php。

Internet Explorer cannot download generate.php from my.domain.

Internet Explorer无法打开此Internet站点。
请求的网站要么不可用,要么找不到。请稍后再尝试

Internet Explorer was not able to open this Internet site. The requested site is either unavailable or cannot be found. Please try again later.

我正在使用的代码( generate.php )如下:

The code that I'm using (generate.php) is as follows:

// Open template
$xlRead = PHPExcel_IOFactory::createReader('Excel5');
$xl = $xlRead->load('Template.xls');

$xl->setActiveSheetIndex(0);

// Write data
$xl->getActiveSheet()->fromArray($dbOutput, null, 'A1');

// Output to browser
header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0', false);
header('Pragma: no-cache');
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename=MyReport.xls');

$xlWrite = PHPExcel_IOFactory::createWriter($xl, 'Excel5');
$xlWrite->save('php://output')






编辑似乎此问题仅在SSL后面影响IE。因此,这与几个类似的SO问题是相同的问题。人们的建议是调整标题,但到目前为止,我看到的解决方案没有任何组合工作......


EDIT Seems like this problem only affects IE when behind SSL. As such, this is an identical problem to several similar SO questions. People's advice is to tweak the headers, but so far, no combination of what I've seen as solutions has worked...

推荐答案

如果以上都不适合您,并且您仍希望在SSL下运行,则可以始终将文件写入磁盘并提供下载链接,或者您可以提示用户输入电子邮件地址并将文件通过电子邮件发送至一个附件。如果你去电子邮件路线,PHPMailer有一个相当简单的方式发送附件。我不是100%肯定,但我认为文件需要在使用PHPMailer附加之前写入磁盘,但您可以在发送后立即取消链接文件。

If none of the above works for you, and you would still like to run under SSL, you could always write the file to disk and provide a download link, or you could prompt the user for an email address and email the file as an attachment. If you go the email route, PHPMailer has a fairly easy way of sending attachments. I'm not 100% for sure, but I think the file needs to be written to disk before it can be attached using PHPMailer, but you can always unlink the file immediately after send.

这篇关于PHPExcel输出到浏览器在IE中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆