I’m using Laravel-Excel to create excel files with Laravel. I need to set page orientation to landscape
, But I can’t find the solution in official documentation. By the way I’m using Blade to create excel file and this is my code.
class ExampleExcel implements FromView, WithEvents { public function view(): View { return view('excel.main'); } public function registerEvents(): array { return [ AfterSheet::class => function(AfterSheet $event) { $event->sheet->getDelegate()->setRightToLeft(true); }, ]; } }
Thanks in advance!
Advertisement
Answer
Consider adding BeforeSheet
event like this.
return [ BeforeSheet::class => function (BeforeSheet $event) { $event->sheet ->getPageSetup() ->setOrientation(PhpOfficePhpSpreadsheetWorksheetPageSetup::ORIENTATION_LANDSCAPE); }, ];