I am using Laravel-5.8 and Maatwebsite-3.1 to export to excel.
While trying to format, I did page setup to orientation
<?php
namespace App\Exports;
use Maatwebsite\Excel\Concerns\FromCollection;
use Maatwebsite\Excel\Concerns\Exportable;
use Maatwebsite\Excel\Concerns\FromQuery;
use Maatwebsite\Excel\Concerns\WithHeadings;
use Maatwebsite\Excel\Concerns\ShouldAutoSize;
use Maatwebsite\Excel\Concerns\WithEvents;
use Maatwebsite\Excel\Events\BeforeExport;
use Maatwebsite\Excel\Events\BeforeWriting;
use Maatwebsite\Excel\Events\BeforeSheet;
use Maatwebsite\Excel\Events\AfterSheet;
use Maatwebsite\Excel\Concerns\FromView;
use PhpOffice\PhpSpreadsheet\Shared\Date;
use PhpOffice\PhpSpreadsheet\Style\NumberFormat;
use Maatwebsite\Excel\Concerns\WithColumnFormatting;
use Maatwebsite\Excel\Concerns\WithMapping;
use \Maatwebsite\Excel\Sheet;
use Maatwebsite\Excel\Concerns\RegistersEventListeners;
use Illuminate\Support\Facades\DB;
class HrEmployeeGoalExport implements FromCollection, ShouldAutoSize, WithHeadings, WithEvents, WithMapping
{
public function registerEvents(): array
{
return [
AfterSheet::class => function(AfterSheet $event) {
$cellRange = 'A1:L1'; // All headers
$event->sheet->getDelegate()->getStyle($cellRange)->getFont()->setName('Calibri')->setSize(14)->setBold($cellRange);
$event->sheet->getDelegate()->getStyle($cellRange)->getFont()->getColor()
->setARGB(\PhpOffice\PhpSpreadsheet\Style\Color::COLOR_WHITE);
$event->sheet->getDelegate()->getStyle($cellRange)->getFill()
->setFillType(\PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID)
->getStartColor()->setARGB('FF17a2b8');
$event->sheet->setAutoFilter($cellRange);
$event->sheet->setOrientation(\PhpOffice\PhpSpreadsheet\Worksheet\PageSetup::ORIENTATION_LANDSCAPE);
},
];
}
}
When I tried to download, I got this error:
production.ERROR: Method Maatwebsite\Excel\Sheet::setOrientation does
not exist. {"userId":469,"exception":"[object]
(BadMethodCallException(code: 0): Method
Maatwebsite\Excel\Sheet::setOrientation does not exist. at
C:\xampp\htdocs\myapp\vendor\laravel\framework\src\Illuminate\Support\Traits\Macroable.php:104)
[stacktrace]
#0 C:\xampp\htdocs\myapp\vendor\maatwebsite\excel\src\DelegatedMacroable.php(29):
Maatwebsite\Excel\Sheet->__call('setOrientation', Array)
And when I used:
$event->sheet->getDelegate()->getPageSetup()->setOrientation(PageSetup::ORIENTATION_LANDSCAPE);
I got this error:
production.ERROR: Class 'App\Exports\PageSetup' not found
How do I get this resolved?
Thanks