gpt4 book ai didi

IE 的 PHP Excel 输出给出空文件

转载 作者:行者123 更新时间:2023-12-04 19:49:31 25 4
gpt4 key购买 nike

我正在尝试用 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 M Y H: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);

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

谢谢,罗兰

最佳答案

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

像这样:

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

关于IE 的 PHP Excel 输出给出空文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3149772/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com