PHP Excel Header(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);
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 标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:PHP Excel 标头
基础教程推荐
- 如何在 PHP 中的请求之间持久化对象 2022-01-01
- WooCommerce 中选定产品类别的自定义产品价格后缀 2021-01-01
- Libpuzzle 索引数百万张图片? 2022-01-01
- XAMPP 服务器不加载 CSS 文件 2022-01-01
- 超薄框架REST服务两次获得输出 2022-01-01
- 在多维数组中查找最大值 2021-01-01
- mysqli_insert_id 是否有可能在高流量应用程序中返回 2021-01-01
- 在 Woocommerce 中根据运输方式和付款方式添加费用 2021-01-01
- 在 PHP 中强制下载文件 - 在 Joomla 框架内 2022-01-01
- 通过 PHP SoapClient 请求发送原始 XML 2021-01-01