How to get excel header and title in Maatwebsite?

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

This returns only items, not header.

Upvotes: 1

Views: 2639

Answers (2)

Sajeed Kannoje
Sajeed Kannoje

Reputation: 1012

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

try this

Upvotes: 0

jedrzej.kurylo
jedrzej.kurylo

Reputation: 40909

You can get file title with:

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

You can also call getTitle() on individual sheets:

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

Upvotes: 1

Related Questions