Cyber-Duck / laravel-excel

This package provides a way to export an Eloquent collection as an excel file and to import a Excel file as an Eloquent collection.
https://www.cyber-duck.co.uk
MIT License
74 stars 27 forks source link

How to skip header (first & second row) when importing excel file #15

Closed jarachanthan closed 4 years ago

jarachanthan commented 4 years ago

I'm trying to import an .xlsx file in Laravel. What I want to achieve is to skip the header (first & second row) of the file.

$filepath = $request->file('file');
$excel = Importer::make('Excel');
$excel->hasHeader(true);
$excel->load($filepath)->setParser(new ParserModel())->getCollection();
$collection = $excel->getCollection();

this is working well with for one row header, but in my case I have two rows as header and how can I achieve this?

SimoTod commented 4 years ago

It's not supported but, as a workaround, Iif the transform function returns false, the row won't be added to the collection.

jarachanthan commented 4 years ago

It's not supported but, as a workaround, Iif the transform function returns false, the row won't be added to the collection.

Thanks for your reply. I changed the code to solve my problem like this (unset the collect). $collection = $excel->getCollection()->skip(1);