setFileName($fileName); } //设置要导出的文件名 public function setFileName($fileName) { $this->fileName = $fileName; } /** * @brief 写入内容操作,每次存入一行 * @param $data array 一维数组 */ public function setTitle($data = array()) { array_walk($data,function(&$val,$key) { $val = "".$val.""; }); $this->_data .= "".join($data).""; } /** * @brief 写入标题操作 * @param $data array 数据 */ public function setData($data = array()) { array_walk($data,function(&$val,$key) { $val = "".$val.""; }); $this->_data .= "".join($data).""; } //开始下载 public function toDownload($data = '') { // Redirect output to a client’s web browser (Excel5) header('Content-Type: application/vnd.ms-excel'); header('Content-Disposition: attachment;filename='.$this->fileName.'_'.date('Y-m-d').'.xls'); header('Cache-Control: max-age=0'); // If you're serving to IE 9, then the following may be needed header('Cache-Control: max-age=1'); // If you're serving to IE over SSL, then the following may be needed header ('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past header ('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); // always modified header ('Cache-Control: cache, must-revalidate'); // HTTP/1.1 header ('Pragma: public'); // HTTP/1.0 $result = $data ? $data : "".$this->_data."
"; echo <<< OEF {$result} OEF; } }