laravel-excel官方文档地址
<?php
namespace App\Exports;
use Illuminate\Contracts\View\View;
use Maatwebsite\Excel\Concerns\FromArray;
use Maatwebsite\Excel\Concerns\WithEvents;
use Maatwebsite\Excel\Concerns\WithHeadings;
use Maatwebsite\Excel\Events\AfterSheet;
class ApplicationExport implements FromArray, WithEvents, WithHeadings
{
protected $array;
public function __construct(array $array)
{
$this->array = $array;
}
/**
* @return array
*/
public function array(): array
{
return $this->array;
}
/**
* @return array
*/
public function headings(): array
{
return [
'类型',
'应用',
'颜色',
'数量',
'图片',
'提交日期'
];
}
public function registerEvents(): array
{
return [AfterSheet::class => function (AfterSheet $event) {
$drawing = new \PhpOffice\PhpSpreadsheet\Worksheet\Drawing();
$drawing->setName('图片');
$drawing->setDescription('图片');
$drawing->setCoordinates("L2");
$drawing->setPath($this->array[0]['image']);
$drawing->setWidth(80);
$drawing->setWorksheet($event->sheet->getDelegate());
}];
}
}