下载.xls会抛出错误 - 文件不是指定的格式

时间:2014-01-20 09:51:50

标签: javascript php

正如标题所指定的,我在下载文件时得到的文件没有指定的格式错误。以下是我的代码。此外,下载的文件没有任何单元格。

    $content = ob_end_flush();
$filename = trim($filename);
$filename = str_replace(array(' ', '/', '\\'), '', $title);
$filename .= "_Export.xls";
header('Content-type: application/vnd.ms-excel; charset=utf-8');
//header('Content-type: application/ms-excel');
header('Content-Disposition: attachment; filename='.$filename);
echo $content;

1 个答案:

答案 0 :(得分:0)

放:

ob_clean();
ob_start();

header('Content-type: application/vnd.ms-excel; charset=utf-8');

并尝试...


变化

header('Content-type: application/vnd.ms-excel; charset=utf-8');

header('Content-type: application/msexcel; charset=utf-8');

header('Content-type: application/octet-stream; charset=utf-8');