讨论数量:
需要自己扩展导出功能
<?php
namespace App\Admin\Exporters;
use Box\Spout\Common\Entity\Style\Color;
use Box\Spout\Writer\Common\Creator\Style\StyleBuilder;
use Box\Spout\Writer\Common\Creator\WriterEntityFactory;
use Dcat\Admin\Exception\RuntimeException;
use Dcat\Admin\Grid\Exporters\ExcelExporter as DcatExcelExporter;
use Dcat\Admin\Grid;
use Dcat\EasyExcel\Excel;
class ExcelExporter extends DcatExcelExporter
{
/**
* {@inheritdoc}
*/
public function export()
{
$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 = (new StyleBuilder())
->setFontBold()
->setFontSize(15)
->setFontColor(Color::BLUE)
->setShouldWrapText(false)
->setBackgroundColor(Color::YELLOW)
->build();
/** Create a row with cells and apply the style to all cells */
return WriterEntityFactory::createRowFromArray(array_values($row), $style);
})->download($filename);
exit;
}
}
使用
use App\Admin\Exporters\ExcelExpoter;
$grid->export(new ExcelExpoter());
推荐文章: