PHPExcel为文件格式设置特定标头

谷歌搜索时,我发现在输出以不同文件格式生成的excel时需要设置两组不同的标题.

例如

对于类型“Excel5”标题是:

header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate,post-check=0,pre-check=0");
header("Content-Type: application/force-download");
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");;
header("Content-disposition: attachment;filename=$filename");
header("Content-transfer-encoding: binary ");

对于类型“Excel2007”标题是:

header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-disposition: attachment;filename="myfile.xlsx"');
header('Cache-Control: max-age=0');

我的问题:是否需要为每种文件类型设置不同的标题,因为还有其他文件类型还包括CSV,HTML和PDF?

header("Pragma: public");

不 – 这是错的 – 虽然很多人认为它与缓存有关

header("Expires: 0");
header("Cache-Control: must-revalidate,pre-check=0");

与Excel无关 – 这些只是控制缓存

header("Content-Type: application/force-download");
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");;

不 – 应该只有一个内容类型标头.对于使用OLE的MS Excel文件,mimetype应为application / vnd.ms-excel

只有上面的第二个标头是有效的mime类型.

header("Content-disposition: attachment;filename=$filename");
header("Content-transfer-encoding: binary ");

第二个标头是冗余的,前者指定下载的文件名.

Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet’);

仅适用于.xlsx文件(即以XML格式保存).否则你应该使用application / vnd.ms-excel.实际上后者应该向后兼容.

My question: is there need to set up different headers for each file type

是 – Content-Type标头是文件类型.但只有这个标题需要改变.

C.

相关文章

统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
前言 之前做了微信登录,所以总结一下微信授权登录并获取用户...
FastAdmin是我第一个接触的后台管理系统框架。FastAdmin是一...
之前公司需要一个内部的通讯软件,就叫我做一个。通讯软件嘛...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...