<?php $objPHPExcel = new PHPExcel(); $objSheet = $objPHPExcel->getActiveSheet(); $array = array( array("規格型號", "產品編號", "描述", "入庫數量", "出庫數量", "當前庫存"), array($spec, $no) ); $objSheet->fromArray($array); $filename = '在庫數據20190508.xls'; $this->startDownload($filename); $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5'); $objWriter->save('php://output'); /** * 生產文件下載須要的響應頭信息。 * @param string $name 文件名稱,可爲中文。 */ function startDownload($name) { $ua = $_SERVER["HTTP_USER_AGENT"]; if (strpos($ua, "MSIE")) $name = "=\"".str_replace("+", "%20", urlencode($name))."\""; elseif (strpos($ua, "Firefox")) $name = "*=\"utf8''".$name."\""; else $name = "=\"".$name."\""; header("Expires: Mon, 26 Jul 1997 05:00:00 GMT\n"); header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); header("Cache-Control: no-cache"); header("Pragma: no-cache"); header("Content-Disposition: attachment; filename".$name); header("Content-type: application/octet-stream"); } ?>