我需要生成一个扩展名为 .xlsx
的 Excel 文件。
这是我的简单代码:
$file = "test.xlsx";
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment; filename='.$file);
$content = "Col1\tCol2\tCol3\t\n";
$content .= "test1\ttest1\ttest3\t\n";
$content .= "testtest1\ttesttest2\ttesttest3\t\n";
echo $content;
但是当我打开生成的文件时出现此错误:
Excel cannot open the file 'test.xlsx' because the file format or file extension is not valid.
有任何想法吗?
原文由 angel enanod 发布,翻译遵循 CC BY-SA 4.0 许可协议
在尝试了几个选项后,我发现
PHP_XLSX_Writer
适合我的需要。”`
更多信息: