jeudi 18 mai 2023

Background image in Maatwebsite excel laravel

I am using laravel 9 and using Maatwebsite. I want to set background image in excel. Here I did

class myExport implements FromView, WithEvents ,WithDrawings
{

  public function view(): View
   {
     return view('report');
   }

   public function drawings()
    {
    $drawing = new Drawing();
    $drawing->setName('Background Text');
    $drawing->setDescription('This text ');
    $drawing->setPath(public_path('assets/img/draft.png'));
    $drawing->setCoordinates('A1'); 

    return [$drawing];
}

Image shows successfully but not appears in background . Thanks inadvance

Also tried with

public function registerEvents(): array
{

    return [
        BeforeSheet::class => function (BeforeSheet $event) {
            $spreadsheet = new Spreadsheet();
            $event->sheet->getDelegate()->setActiveSheetIndex(0);
            $event->sheet->getDelegate()->getActiveSheet()
                ->getHeaderFooter()
                ->setOddFooter('&L&BPage &P of &N');

            $event->sheet->getDelegate()->getActiveSheet()
                ->setShowGridlines(false); // Optional: Hide gridlines

            $event->sheet->getDelegate()->getActiveSheet()
                ->setSheetBackground('assets/img/draft.png'); 
        },
    ]; 


via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire