问题描述
header(Content-Type:application / vnd.ms-excel; charset = utf-8);
header(Content-type:application / x-msexcel; charset = utf-8);
header(Content-Disposition:attachment; filename = abc.xsl);
header(Expires:0);
header(Cache-Control:must-revalidate,post-check = 0,pre-check = 0);
header(Cache-Control:private,false);
echoSome Text
这里是使用php编写和下载xsl文件的代码,
我的问题是当我打开excel文件MS-Excel在打开文件之前显示警告说
如何使用PHP代码删除此代码警告?内容写入正确。
我知道这是因为写入文件的内容是txt文件内容,文件扩展名不正确,即xls。解决方案?
请不要建议使用任何库。
您正在给出多个 Content-Type
标题。 application / vnd.ms-excel
就足够了。
还有一些语法错误。在echo语句中使用;
语句和错误的文件扩展名来终止语句。
header(Content-Type:application / vnd.ms-excel; charset = utf-8);
header(Content-Disposition:attachment; filename = abc.xls); //文件扩展名错误
header(Expires:0);
header(Cache-Control:must-revalidate,post-check = 0,pre-check = 0);
header(Cache-Control:private,false);
回显某些文字; //不结束;这里
header("Content-Type: application/vnd.ms-excel; charset=utf-8");
header("Content-type: application/x-msexcel; charset=utf-8");
header("Content-Disposition: attachment; filename=abc.xsl");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private",false);
echo "Some Text"
Here is code to write and download xsl file using php,
my problem is when i open excel file MS-Excel show warning before opening file says
What's to do with PHP code to remove this warning? Contents are written correctly.
I know this is because content written in file are txt file content and file extension is incorrect, that is, xls. Solution?
Please don't suggest to use any library.
You are giving multiple Content-Type
headers. application/vnd.ms-excel
is enough.
And there are couple of syntax error too. To statement termination with ;
on the echo statement and wrong filename extension.
header("Content-Type: application/vnd.ms-excel; charset=utf-8");
header("Content-Disposition: attachment; filename=abc.xls"); //File name extension was wrong
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private",false);
echo "Some Text"; //no ending ; here
这篇关于PHP Excel头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!