问题描述
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"
这是使用 php 编写和下载 xsl 文件的代码,
我的问题是当我打开 excel 文件时 MS-Excel 在打开文件之前显示警告说
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
您尝试打开的文件的格式与文件扩展名指定的格式不同...废话
The file you are trying to open is in different format than specified by the file extension...Blah blah
如何处理 PHP 代码来消除此警告?内容书写正确.
What's to do with PHP code to remove this warning? Contents are written correctly.
我知道这是因为文件中写入的内容是txt文件内容,文件扩展名不正确,即xls.解决方案?
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.
推荐答案
您提供了多个 Content-Type 标头.application/vnd.ms-excel 就够了.
You are giving multiple Content-Type headers. application/vnd.ms-excel is enough.
还有一些语法错误.在 echo 语句和错误的文件扩展名上使用 ; 终止语句.
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 标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!



大气响应式网络建站服务公司织梦模板
高端大气html5设计公司网站源码
织梦dede网页模板下载素材销售下载站平台(带会员中心带筛选)
财税代理公司注册代理记账网站织梦模板(带手机端)
成人高考自考在职研究生教育机构网站源码(带手机端)
高端HTML5响应式企业集团通用类网站织梦模板(自适应手机端)