<?phpnamespaceApp\Admin\Exporters;useBox\Spout\Common\Entity\Style\Color;useBox\Spout\Writer\Common\Creator\Style\StyleBuilder;useBox\Spout\Writer\Common\Creator\WriterEntityFactory;useDcat\Admin\Exception\RuntimeException;useDcat\Admin\Grid\Exporters\ExcelExporteras DcatExcelExporter;useDcat\Admin\Grid;useDcat\EasyExcel\Excel;classExcelExporterextendsDcatExcelExporter{/**
* {@inheritdoc}
*/publicfunctionexport(){$filename=$this->getFilename().'.'.$this->extension;$exporter=Excel::export();if($this->scope===Grid\Exporter::SCOPE_ALL){$exporter->chunk(function(int $times){return$this->buildData($times);});}else{$exporter->data($this->buildData()?:[[]]);}$exporter->headings($this->titles())->row(function($row){/** Create a style with the StyleBuilder */$style=(newStyleBuilder())->setFontBold()->setFontSize(15)->setFontColor(Color::BLUE)->setShouldWrapText(false)->setBackgroundColor(Color::YELLOW)->build();/** Create a row with cells and apply the style to all cells */returnWriterEntityFactory::createRowFromArray(array_values($row),$style);})->download($filename);exit;}}
需要自己扩展导出功能
使用