【问题标题】:Maatwebsite Excel - how to name multiple sheets?Maatwebsite Excel - 如何命名多张工作表?
【发布时间】:2020-11-21 13:53:21
【问题描述】:

我有一个 Maatwebsite (v3.1.25) Excel Export,如下所示。为每张工作表添加自定义名称的最简单方法是什么?目前它们只显示为“工作表”、“工作表 1”等。

我确实看过官方网站的文档,但无法弄清楚如何将其应用于我的具体情况。

class BizdevReport implements WithMultipleSheets
{


    public function sheets(): array
    {
        $sheets = [
            new BizdevReportTeachers(),
            new BizdevReportClasses(),
            new BizdevReportGMV()
        ];

        return $sheets;
    }


}

【问题讨论】:

    标签: laravel laravel-5 maatwebsite-excel


    【解决方案1】:

    我正在尝试帮助回答。

    虽然您在 9 个月前问过,但也许这对需要答案的人有用。

    BizdevReportTeachers 类中,实现WithTitle 并添加title 函数

    use Maatwebsite\Excel\Concerns\WithTitle;
    
    class BizdevReportTeachers implements WithTitle
    {
         public function title(): string
         {
              return 'Lorem Ipsum';
         }
    }
    

    参考:https://docs.laravel-excel.com/3.1/exports/multiple-sheets.html

    【讨论】:

      【解决方案2】:

      你快到了。只需将您需要的名称添加到工作表数组中,如下所示

      类 BizdevReport 实现 WithMultipleSheets {

      public function sheets(): array
      {
          $sheets = [
            'BizdevReportTeachers' =>  new BizdevReportTeachers(),
            'BizdevReportClasses' =>  new BizdevReportClasses(),
            'BizdevReportGMV' =>  new BizdevReportGMV()
          ];
      
          return $sheets;
        }
      }
      

      就是这样。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-11-04
        • 1970-01-01
        • 1970-01-01
        • 2021-10-13
        • 2019-01-22
        相关资源
        最近更新 更多