【发布时间】:2019-11-28 18:20:06
【问题描述】:
我正在开发一项功能,我正在向用户证明 excel 转储。当用户下载 excel 表时,它工作正常。当用户尝试使用 Microsoft Excel 打开时,它给我一个错误“Excel 无法打开文件,因为文件格式或扩展名无效”这仅在 Firefox 浏览器中发生,并且在文件名中自动添加 .xlsx 扩展名。
我用来创建 excel 转储的代码是
header('Pragma: public');
header("Expires: Mon, 12 Jul 2012 05:00:00 GMT"); // Date in the past
header('Content-Disposition: attachment; filename="excel.xls"');
header('Last-Modified: '.gmdate('D, d M Y H:i:s') . ' GMT');
header('Cache-Control: no-store, no-cache, must-revalidate'); // HTTP/1.1
header('Cache-Control: pre-check=0, post-check=0, max-age=0');
$header = "Date\t";
$header .= "Other Details Details\t";
echo $header . "\n";
echo "Date1\t";
echo "Detail1\t\n";
echo "Date2\t";
echo "Detail2\t\n";
【问题讨论】:
-
.xlsx 文件只能在 Microsoft Excel 2007+ 中打开,您确定您尝试打开它的那些计算机具有该版本的 Excel?
-
是的,我使用的是 Excel 2007,而且我尝试下载的格式是 .xls
-
你找到根本原因和解决方案了吗?