【发布时间】:2011-05-19 20:32:39
【问题描述】:
我有这个脚本可以将 mysql 数据导出到 excel。我试过了 一切,但我无法让这个脚本为 IE 工作。这 脚本使用 FireFox 或 Chrome 下载数据,但 IE 失败并且 说:
Internet Explorer 无法从 www.mysite.com 下载 list_view.php。 (这是文件所在的站点)。
Internet Explorer 无法 打开此 Internet 站点。请求的站点不可用或 找不到。请稍后再试。
这是我正在使用的代码:
$sql = "SELECT...."
$result = mysql_query($sql)
or die("\nError Retrieving Records.<hr />sql: $sql<hr />ERROR:".mysql_error());
if(mysql_num_rows($result) > 0){
// build a filename that excel will use to save it as
$filename=$name."_".dateFromDB($_GET['confDate']).".xls";
// headers to force the open/save into Excel
header("Content-Type: application/vnd.ms-excel");
header("Content-Disposition: attachment; filename=$filename");
header("Pragma: no-cache");
header("Expires: 0");}?>
<table>
<thead>
<tr>
<th>address</th>
<th>phone</th>
<th>email</th>
<th>status</th>
</tr>
</thead>
<tbody>
<?php // loop over items
while ($row = mysql_fetch_array ($result, MYSQL_ASSOC)) { ?>
<tr>
<td><?=$row['address'];?></td>
<td><?=$row['phone'];?></td>
<td><?=$row['email'];?></td>
<td><?=$row['status'];?></td>
</tr><?php
}?>
</tbody>
</table><?php
exit(); // exit or it will throw an error when it tries to continue
我知道可能有人建议不要使用IE,但实际使用导出功能的人无法访问其他浏览器。
编辑:
我忘了提到我正在运行 SSL(https)。如果我关闭 SSL,IE 上一切正常,但 SSL 在 IE 上的那一刻显示错误。
任何想法如何使它在 SSL 下工作?
【问题讨论】:
-
IE 有一些非常愚蠢的缓存逻辑,因为一切都通过浏览器缓存传递,包括下载。使用 no-cache pragma,您可以告诉 IE 在下载完成后立即删除下载,然后才会弹出保存文件对话框。
-
那你有什么建议?我试过没有那条线,但仍然不能为 IE 工作
-
同时删除 expires 标头。
-
仍然无法工作...有没有我可以使用的工作脚本?
-
你可以尝试使用PHPExcel并生成一个真正的Excel文件,而不是一些伪装成Excel的html。
标签: php mysql excel ssl export-to-excel