doutan5798 2012-08-29 09:36 采纳率: 100%
浏览 52
已采纳

PHPExcel输出到浏览器在IE中不起作用

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 cannot download generate.php from my.domain.

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

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')

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...

  • 写回答

2条回答 默认 最新

  • ds08541 2012-10-17 16:13
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度