我正在尝试使用laravel excel导出,其中有自定义标头。像这样:
我正在使用Laravel Excel 3,它使用FromQuery,WithTitle,WithHeadings。
我可以使用withheadings数组实现所需输出的一半,但其余部分无法实现
<?php
namespace App\Exports;
use Modules\Report\Entities\Aereport;
use Maatwebsite\Excel\Concerns\FromQuery;
use Maatwebsite\Excel\Concerns\WithTitle;
use Maatwebsite\Excel\Concerns\WithHeadings;
use Maatwebsite\Excel\Concerns\ShouldAutoSize;
class AereportPerDaySheet implements FromQuery, WithTitle, WithHeadings, ShouldAutoSize
{
private $year;
private $day;
private $month;
public function __construct(int $year, int $month, int $day)
{
$this->year = $year;
$this->day = $day;
$this->month = $month;
}
/**
* @return Builder
*/
public function query()
{
return Aereport::select('report_id','dateofreport','date','url','username','reportertype','productname','verbatim','priority','aeraised')->whereMonth('dateofreport', $this->month)->whereday('dateofreport', $this->day);
}
/**
* @return string
*/
public function title(): string
{
return $this->day .' '. date("F", mktime(0,0,0,$this->month,1)) .' '. $this->year;
}
public function headings(): array
{
return[
'Id',
'Date issue was found',
'URL',
'Username',
'Reporter Type',
'Product Name',
'Verbatim',
'Priority',
];
}
}
如图所示,我能够获取标头,但不能获得所述定制。