PHP的Excel输出为IE提供空文件

我想用PHP生成一个excel文件。 这在Firefox中正常工作,但与IE浏览器我只是得到一个空的文件。 这就是我正在做的事情:

header('Content-type: application/ms-excel'); header('Content-Disposition: inline; attachment; filename='.$filename); echo $data; 

我已经尝试了各种标题设置,但没有成功。 我也试图输出内容作为文本文件,在这里相同的结果。 在IE中没有内容。

有任何想法吗?

 header("Cache-Control: no-stor,no-cache,must-revalidate"); header("Cache-Control: post-check=0,pre-check=0", false); header("Cache-control: private"); header("Content-Type: application/octet-stream"); header('Content-Disposition: inline; attachment; filename='.$filename); header("Content-Transfer-Encoding: binary"); header("Pragma: no-cache"); header("Expires: 0"); 

 header('Pragma: public'); header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); header('Last-Modified: '.gmdate('D, d MYH:i:s') . ' GMT'); header('Cache-Control: no-store, no-cache, must-revalidate'); header('Cache-Control: pre-check=0, post-check=0, max-age=0'); header ("Pragma: no-cache"); header("Expires: 0"); header('Content-Transfer-Encoding: none'); header('Content-Type: application/vnd.ms-excel;'); header("Content-type: application/x-msexcel"); header('Content-Disposition: inline; attachment; filename='.$filename); 

只是两个选项,也尝试了一些其他的组合。

谢谢,罗兰

有同样的问题:即使TCP连接仍然打开,如果它没有得到响应,IE会在一段时间后超时。 什么帮助我是这样的:禁用输出缓冲,发送标题并将其清除。 发送数据时,你有他们。 这足以保持连接的开放。

像这样的东西:

 // reset all output buffering while (ob_get_level() > 0) { ob_end_clean(); } header('Content-type: application/ms-excel'); header('Content-Disposition: inline; attachment; filename='.$filename); // we can't send any more headers after this flush(); $excel = new PhpExcel(); $excel->setActiveSheetIndex(0); $sheet = $excel->getActiveSheet(); // in this example, $data was an array in the format row => value // data structure is not relevant to issue foreach ($data as $key => $value) { // add data to sheet here $sheet->SetCellValue('A' . $key, $value); // etc... } $writer = new PHPExcel_Writer($excel); // push to browser $writer->save('php://output'); 

将您的标题设置为header("Content-Type: application/octet-stream"); 强制下载。

或者你的头文件的另一个版本是添加vnd所以application/vnd.ms-excel但是如果你发送这个头文件,那么你也应该把你的当前头文件放在一边,因为一些浏览器有所不同。