文档:
Exporting collections | Laravel Excel
导出类
class TestExport implements FromArray {
protected $invoices;
protected $columns = ['姓名','性别'];
public function __construct(array $invoices)
{
$this->invoices = array_merge([$this->columns], $invoices);
}
public function array(): array
{
return $this->invoices;
}
}
控制器方法
public function export_action(){
return Excel::download(new TestExport($data), $name.'.xlsx');
}