0

此输出存在问题。当用户单击按钮时,它应该吐出一个 excel 表。但是,对于某些用户,它会输出一个 HTML 页面。我感觉这与其他使用 IE7 而不是 IE10 的用户有关。但是,此功能应该适用于两者。

请帮忙。

如果您能发现错误,请告诉我:

$time = time();
$illegals = array('!', '*', "'", ";", ":", "@", "&", "=", "+", "$", ",", "/", "?", "%", "#", "[", "]", "\"");
if(isset($_GET['ns_title'])) {$filename = str_replace($illegals,"",urldecode($_GET['ns_title'])).".xls"; } else { $filename = "myreport$time.xls"; }
header("Content-type: application/force-download"); 
header("Content-Transfer-Encoding: Binary");    
header("Content-type: application/octet-stream");
header('Content-Disposition: attachment; filename="'.$filename.'"'); 
header("Expires: 0");

print "$headers\n$data";
4

2 回答 2

0

您正在指定两种类型的Content-type's - 坚持application/octet-stream或提供实际的 Excel 内容类型(请参阅 Bastien 的回答)。

其次,什么是$headers$data?我们假设您正在使用那些认为他们设置标题的人 - 但header()已经这样做了。

如果它是一个真实文件,您可以使用readfile($filename)它,或者只是回显您想要开始浏览器下载的内容。

于 2013-07-02T14:26:44.880 回答
0

试试这个官方的 MIME 类型application/vnd.ms-excel

于 2013-07-02T14:27:23.443 回答