use*_*624 14 php header fwrite phpexcel
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"
Run Code Online (Sandbox Code Playgroud)
这里是使用php编写和下载xsl文件的代码,
我的问题是当我打开excel文件MS-Excel显示警告之前打开文件说
您尝试打开的文件格式与文件扩展名指定的格式不同... Blah blah
有什么与PHP代码删除此警告?内容写得正确.
我知道这是因为文件中写的内容是txt文件内容,文件扩展名不正确,即xls.解?
请不要建议使用任何库.
Sta*_*arx 31
你给了多个Content-Type标题.application/vnd.ms-excel足够.
并且还有一些语法错误.语句终止与;echo语句和错误的文件扩展名.
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
Run Code Online (Sandbox Code Playgroud)
试试这个
header("Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
header("Content-Disposition: attachment;filename=\"filename.xlsx\"");
header("Cache-Control: max-age=0");
Run Code Online (Sandbox Code Playgroud)