Maatwebsite如何获取excel header和title?

How to get excel header and title in Maatwebsite?

Excel::load($file->getRealPath())->get();

这returns只有项目,没有header。

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

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

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

foreach ($file->get() as $sheet) {
  echo $sheet->getTitle();
}
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',
        ];
    }
}

试试这个