PHP Excel头 [英] PHP Excel Header

查看:177
本文介绍了PHP Excel头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  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在打开文件之前显示警告说


试图打开格式不同于文件扩展名所指定的格式... Blah blah

如何使用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

The file you are trying to open is in different format than specified by the file extension...Blah blah

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头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆