把生成的excel文件直接提供为下载页效果

把php中的excel显示下载页下载到本地硬盘需要设置头信息:

代码:

$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
header("Pragma: public");
header("Expires: 0");
header("Cache-Control:must-revalidate, post-check=0, pre-check=0");
//设置http协议,下载支持
header("Content-Type:application/force-download");
//设置下载的内容是excel
header("Content-Type:application/vnd.ms-execl");
//把下载的内容设置为8机制流内容
header("Content-Type:application/octet-stream");
//设置http协议,下载支持
header("Content-Type:application/download");
//下载excel名字的定义
header('Content-Disposition:attachment;filename="商品信息.xlsx"');
//内容设置为二进制形式传输
header("Content-Transfer-Encoding:binary");
//把excel文件直接提供为下载形式
$objWriter->save('php://output');
原文地址:https://www.cnblogs.com/yangzailu/p/6074507.html