在Laravel中使用自定义标题和多张表格导出Excel

时间:2019-05-31 03:56:31

标签: php laravel

我正在尝试使用laravel excel导出,其中有自定义标头。像这样:

enter image description here

我正在使用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',                        
        ];
    }
}

enter image description here

如图所示,我能够获取标头,但不能获得所述定制。

0 个答案:

没有答案