3

我能够通过 php 输出一个 excel 文件,它可以在 excel 中正确打开。那里没有问题。当用户在 Excel 中单击另存为时,它带有第一个选项 .txt 我如何设置标题,以便第一个选项将 .xls 与另存为。我现在使用的标题:

$filename="jaar.xls";
header("Content-Type: application/vnd.ms-excel");
header("Content-Disposition: attachment; filename=$filename");
header("Pragma: no-cache");
header("Expires: 0");

提前致谢

4

3 回答 3

1

如果你的名字中有空格,你应该尝试引用它:

header("Content-Disposition: attachment; filename='$filename'");
于 2010-08-24T09:53:46.730 回答
1

解决方案是使用 phpexcel http://phpexcel.codeplex.com/

如果使用的 xls 文件是用 /t 构建的,就像文本文件一样,它将像 txt 文件一样被 excel 处理

于 2010-10-05T13:54:15.440 回答
0
header("Content-Disposition: attachment; filename=".$filename);

这足以保存为excel文件

于 2016-05-13T09:43:10.280 回答