1.实现WithEvents接口
class AssertExplore implements FromCollection,WithMapping,WithHeadings,WithEvents
{
protected $ini_arr=[];
public function __construct($ini_arr)
{
$this->ini_arr=$ini_arr;
}
public function map($row): array
{
return [
$row->fd_id,
$row->fd_name,
$row->fd_code,
$row->fd_standard,
$row->fd_first_used_date=date('Y-m-d',strtotime($row->fd_first_used_date))
];
}
public function collection()
{
return (new AssertRepository())->exploreAssert($this->ini_arr);
}
public function headings(): array
{
return [
'地址',
'资产名称',
'资产编码',
'资产型号',
'时间'
];
}
//更多方法查看Worksheet.php源码,此处从calculateColumnWidths方法得知
public function registerEvents(): array
{
return [
AfterSheet::class => function(AfterSheet $event) {
$event->sheet->getDelegate()->getColumnDimension('A')->setWidth('134');
$event->sheet->getDelegate()->getColumnDimension('B')->setWidth('30');
$event->sheet->getDelegate()->getColumnDimension('C')->setWidth('20');
$event->sheet->getDelegate()->getColumnDimension('D')->setWidth('40');
$event->sheet->getDelegate()->getColumnDimension('E')->setWidth('30');
},
];
}
}
参考地址:https://learnku.com/laravel/t/24161