Laravel Excel 怎么根据参数导出自定义列
nova 版本的有看到,docs.laravel-excel.com/nova/1.x/ex...
但是我不是 nova 版本的,普通的。
我现在的代码是
<?php
namespace App\Exports;
use App\Models\MedicineType;
use Maatwebsite\Excel\Concerns\FromCollection;
use Maatwebsite\Excel\Concerns\WithMapping;
use Maatwebsite\Excel\Concerns\WithHeadings;
use Maatwebsite\Excel\Concerns\Exportable;
use Maatwebsite\Excel\Concerns\ShouldAutoSize;
class MedicineTypeExport implements FromCollection, WithMapping, WithHeadings, ShouldAutoSize
{
use Exportable;
public function collection()
{
return MedicineType::listExport();
}
public function map($row): array
{
return [
$row->name ?? '',
$row->legal_name ?? '',
$row->en_name ?? '',
$row->ucode_b ?? '',
$row->category ?? '',
];
}
public function headings(): array
{
return [
'药品名称',
'药品法定名称',
'药品英文名称',
'药品唯一标识符',
'所属药品品种',
];
}
}
(new MedicineTypeExport)->download('药品管理-药品大类导出.xlsx');
需要
比如,导出时,我只需要传入 name、en_name,下载的 Excel 中只有显示这两列。
推荐文章: