Laravel:如何在Excel导出文件中添加页眉,页脚和徽标图像?

时间:2020-08-05 15:10:01

标签: php excel laravel file export

我正在使用MaatWebsite软件包。 这是我的Excel导出类:

use Illuminate\Contracts\View\View;
use Maatwebsite\Excel\Concerns\FromView;
use Maatwebsite\Excel\Concerns\WithHeadings;
use Maatwebsite\Excel\Concerns\ShouldAutoSize;
use Maatwebsite\Excel\Concerns\WithEvents;
use Maatwebsite\Excel\Events\AfterSheet;
use PhpOffice\PhpSpreadsheet\Style\NumberFormat;
use Maatwebsite\Excel\Concerns\WithColumnFormatting;


class ReleaseExportView implements FromCollection, WithHeadings, ShouldAutoSize, WithEvents
{
protected $shipment_id;
function __construct($shipment_id) {
    $this->shipment_id = $shipment_id;
}

public function collection()
{
  

    return outbound_detail::where('shipment_id',$this->shipment_id)->get([
        'shipment_id', 'sku_parent', 'cases'
    ]);
}

public function headings(): array
{
    return [

        'SHIPMENT ID',
        'SKU',
        'CASES TO BE RELEASED'
    ];
 }
 // ...

/**
 * @return array
 */
public function registerEvents(): array
{
    return [
        AfterSheet::class    => function(AfterSheet $event) {
            $cellRange = 'A1:C1'; // All headers
            $event->sheet->getDelegate()->getStyle($cellRange)->getFont()->setSize(14);
            },
    ];
}
 }

现在,当我导出此文件时,它只需下载一个具有给定标头和从数据库中获取的数据的Excel文件。我想在顶部(如果可能的话)添加徽标图像,包含有关公司信息(例如地址等)的页眉以及带有一些文本的页脚。

0 个答案:

没有答案