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 "); 第二个标头是冗余的,前者指定下载的文件名.
仅适用于.xlsx文件(即以XML格式保存).否则你应该使用application / vnd.ms-excel.实际上后者应该向后兼容.
是 – Content-Type标头是文件类型.但只有这个标题需要改变. C. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |