objExcel = new \PHPExcel(); } //设置文件名称 public function SetTitle($name) { $objActSheet = $this->objExcel->getActiveSheet(); $objActSheet->setTitle($name); } //设置表头 public function SheetIndex() { $this->objExcel->setActiveSheetIndex() ->setCellValue('A1',"编号") ->setCellValue('B1',"楼盘名称") ->setCellValue('C1',"区域"); // return $this->objExcel; } //谁知表格内容 从第二行开始 public function SheetText($data,$num = 2) { $i = $num; if(!empty($data)) { foreach ($data as $key=>$val) { $this->objExcel->getActiveSheet() ->setCellValue('A'.$i,$val['id']) ->setCellValue('B'.$i,$val['name']) ->setCellValue('C'.$i,$val['city_name']); $i++; } } } public function Export($fileName) { // $objWriter = \PHPExcel_IOFactory::createWriter($this->objExcel, 'Excel2007'); // $objWriter->save('house.xlsx'); header('Content-Type:application/vnd.ms-excel'); header('Content-Disposition:attachment;filename="'.$fileName.'"'); header('Cache-Control:max-age=0'); $objWriter =\PHPExcel_IOFactory::createWriter($this->objExcel, 'Excel5'); $objWriter->save('php://output'); exit; unset($objWriter); } }