3

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');
Roman Meyer
  • 2,634
  • 2
  • 20
  • 27
Esternome
  • 33
  • 2
  • 7
  • https://github.com/Maatwebsite/Laravel-Excel/issues/1799, https://docs.laravel-excel.com/3.0/getting-started/upgrade.html check this out. seems like you should now use native methods of PhpSpreadsheet – Roman Meyer Mar 14 '21 at 21:25
  • I edited the question and the answer is great and so useful. Reopen de question for community please. – Esternome Mar 15 '21 at 22:15
  • you should probably add your old code (which you used in version 2.1) to clarify a bit more the problem – Roman Meyer Mar 15 '21 at 22:19
  • Done! Thanks @roman-bobrik. I never used it before for my excel, but I understand that it will be better to ask like this with code example. – Esternome Mar 15 '21 at 22:31

1 Answers1

4

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

Roman Meyer
  • 2,634
  • 2
  • 20
  • 27