把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');