【问题标题】:How to get excel header and title in Maatwebsite?如何在 Maatwebsite 中获取 excel 标题和标题?
【发布时间】:2022-01-12 16:12:03
【问题描述】:
Excel::load($file->getRealPath())->get();

这只会返回项目,而不是标题。

【问题讨论】:

    标签: laravel maatwebsite-excel


    【解决方案1】:

    您可以通过以下方式获取文件标题:

    $file = Excel::load($file->getRealPath())
    $file->getTitle();
    

    您还可以在单​​个工作表上调用 getTitle()

    foreach ($file->get() as $sheet) {
      echo $sheet->getTitle();
    }
    

    【讨论】:

      【解决方案2】:
      use Maatwebsite\Excel\Concerns\WithProperties;
      
      class InvoicesExport implements WithProperties
      {    
          public function properties(): array
          {
              return [
                  'creator'        => 'Patrick Brouwers',
                  'lastModifiedBy' => 'Patrick Brouwers',
                  'title'          => 'Invoices Export',
                  'description'    => 'Latest Invoices',
                  'subject'        => 'Invoices',
                  'keywords'       => 'invoices,export,spreadsheet',
                  'category'       => 'Invoices',
                  'manager'        => 'Patrick Brouwers',
                  'company'        => 'Maatwebsite',
              ];
          }
      }
      

      试试这个

      【讨论】:

        猜你喜欢
        • 2023-03-19
        • 1970-01-01
        • 2020-04-03
        • 1970-01-01
        • 2017-01-23
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多