php Excel文件的标题另存为
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3555226/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
header for excel file save as
提问by Grumpy
im able to output an excel file by php and it opens correctly in excel. No problems there. When the user clicsk save as in Excel it comes with first option .txt How can i set the header so first option will .xls with save as. Headers im using now :
我能够通过 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");
Thanks in advance
提前致谢
采纳答案by Grumpy
the solution is to use phpexcel http://phpexcel.codeplex.com/
解决方案是使用phpexcel http://phpexcel.codeplex.com/
if the xls file used is build with /t like a textfile it will be handled like a txt file by excel
如果使用的 xls 文件是用 /t 构建的,就像文本文件一样,它会像 txt 文件一样被 excel 处理
回答by Lekensteyn
If your name has spaces in it, you should try quoting it:
如果你的名字中有空格,你应该尝试引用它:
header("Content-Disposition: attachment; filename='$filename'");
回答by Vishnu Jayan
header("Content-Disposition: attachment; filename=".$filename);
This is enough to save as excel file
这足以保存为excel文件