【问题标题】:Is there a way to freeze the first row of the excel with Laravel Excel 3.1?有没有办法用 Laravel Excel 3.1 冻结 excel 的第一行?
【发布时间】:2021-06-12 04:44:48
【问题描述】:

我在 Laravel 5.8 项目中使用 maatwebsite/excel 3.1。

我需要在导出 excel 时将第一行设置为固定。 version 2.1 as Freeze rows 中已知的内容。

Excel::create('Filename', function($excel) {
   $excel->sheet('Sheetname', function($sheet) {
       $sheet->freezeFirstColumn();
   });
})->export('xls');

【问题讨论】:

标签: php laravel laravel-excel


【解决方案1】:

从版本 3 开始,您应该使用 PhpSpreadsheet 的本机方法。

你可以试试这样的:

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
            },
        ];
    }
}

您可以在这里找到更多信息:

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

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

【讨论】:

  • 谢谢!这是完美的。
  • 这里重要但缺少的部分是您需要使用导出类实现 WithEvents。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-06-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-08-11
  • 2022-11-18
相关资源
最近更新 更多