此文引用作者:
好久没有用maatwebsite/excel都出3.1了,看着完全一脸懵,度娘上也全是2.1的教程,先来个简单的导入导出练练手!
composer require maatwebsite/excel
$app->register(Maatwebsite\Excel\ExcelServiceProvider::class);
<?php
namespace App\Exports;
use App\Invoice;
use Maatwebsite\Excel\Concerns\FromArray;
class InvoicesExport implements FromArray
{
protected $invoices;
public function __construct(array $invoices)
{
$this->invoices = $invoices;
}
public function array(): array
{
return $this->invoices;
}
}
use App\Exports\InvoicesExport;
use Maatwebsite\Excel\Facades\Excel;
public function exportExcel(){
$arr = [
[‘姓名‘, ‘地址‘, ‘性别‘,可加字段‘],
[4, 5, 6],
[这里就是你的数据库对应字段数据]
];
$export = new InvoicesExport($arr);
$bool = Excel::download($export, ‘invoices.xlsx‘;);
return $bool;
}
Lumen中使用 maatwebsite/excel~3.1导入导出
原文:https://www.cnblogs.com/smilevv/p/13518588.html