Is there a way to freeze the first row of the excel with Laravel Excel 3.1? [closed]

I´m using maatwebsite/excel 3.1 in Laravel 5.8 project.

I need to set the first row fixed when exporting the excel. What was known in version 2.1 as Freeze rows.

Excel::create('Filename', function($excel) {

   $excel->sheet('Sheetname', function($sheet) {

       $sheet->freezeFirstColumn();

   });

})->export('xls');

Answer

Since version 3 you should use native methods of PhpSpreadsheet.

You can try something like that:

class SomeExport implements ... // what you need to implement 
{
    // some other code
    
    public function registerEvents(): array
    {
        return [
            AfterSheet::class => function(AfterSheet $event) {
                $workSheet = $event->sheet->getDelegate();
                $workSheet->freezePane('A2'); // freezing here
            },
        ];
    }
}

More info you can find here:

Upgrade: https://docs.laravel-excel.com/3.0/getting-started/upgrade.html

Events: https://docs.laravel-excel.com/3.1/imports/extending.html#events

Leave a Reply

Your email address will not be published. Required fields are marked *