使用这个php依赖扩展非常简单,直接引入
composer require phpoffice/phpexcel
使用方式按下面这样
$objPHPExcel = new \PHPExcel(); try { $objSheet = $objPHPExcel->getActiveSheet(); //工作表标题 $objSheet->setTitle("外呼结果"); //第一行内容,放列标题 $objSheet->setCellValue("A1", "城市"); $objSheet->setCellValue("B1", "阿姨姓名"); $objSheet->setCellValue("C1", "阿姨手机号"); $objSheet->setCellValue("D1", "渠道"); $objSheet->setCellValue("E1", "创建时间"); //设置第一行的背景颜色 $objPHPExcel->getActiveSheet() ->getStyle('A1:E1') ->getFill() ->setFillType(\PHPExcel_Style_Fill::FILL_SOLID) ->getStartColor() ->setRGB('FFFF00'); //后面行循环放内容 for($i=2;$i<10;$i++){ $objSheet->setCellValue("A".$i, "北京"); $objSheet->setCellValue("B".$i, "陶士涵"); $objSheet->setCellValue("C".$i, "18805419888\t"); $objSheet->setCellValue("D".$i, "外呼"); $objSheet->setCellValue("E".$i, "2021-08-1 19:17:36\t"); } $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007'); $fileName=storage_path("outcall_result.xlsx"); $objWriter->save($fileName); } catch (\PHPExcel_Exception $e) { }
在laravel 框架中storge目录下,生成excel