getProperties()->setCreator($author) ->setLastModifiedBy($author) ->setTitle($author) ->setSubject($author) ->setDescription($author) ->setKeywords($author) ->setCategory($author); //设置excel工作表名及文件名 $title = $data['title']; $objPHPExcel->getActiveSheet()->setTitle($title); $objPHPExcel->getActiveSheet()->getRowDimension('1')->setRowHeight(25); if(!isset($data['list'])){ throw new \Exception("缺少数据"); } foreach ($data['list'] as $index => $item){ $rowIndex = $index + 1; for($k=0; $k < count($item); $k++){ $pos = self::getSheetColIndex($k+1).$rowIndex; if($style == "default"){ $objPHPExcel->getActiveSheet()->setCellValue($pos,$item[$k]); if($rowIndex == 1){ $objPHPExcel->getActiveSheet()->getStyle($pos)->getFont()->setSize(10)->setBold(true); $objPHPExcel->getActiveSheet()->getStyle($pos)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER); } } else { $objPHPExcel->getActiveSheet()->setCellValue($pos,$item[$k]); } } } $exportPath = dirname($filename); $exportPath = trim($exportPath,"."); $exportPath = trim($exportPath,"/"); if(!file_exists($exportPath) && strlen($exportPath)){ self::mkDir($exportPath); } $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007'); $objWriter->save($filename); if(file_exists($filename)){ return $filename; } throw new \Exception("文件导出失败"); } public static function csv() { } //目录创建(递归创建) public static function mkDir($dir, $mode = 0777) { return is_dir($dir) or self::mkDir(dirname($dir), $mode) and mkdir($dir, $mode); } }