Laravel-excel: Use second row as collection attributes

Created on 9 Jun 2015  路  8Comments  路  Source: Maatwebsite/Laravel-Excel

I am dealing with large excel file for amazon product.

Here importing file, collection attributes consider as a first row alway, but in some case first raw may be description, title of image. So we must ignore it for expected result.

image

And this gives me wrong result as below

image

So how can i use manual row as a header of data ?

Most helpful comment

Use Config::set()

can you give an example with parameters?

All 8 comments

You can change the startrow in the import config

Ok thanks

But is there any way to change config on fly.

Because if i have two excel, first has first row as a header & second has second so.

Use Config::set()

Use Config::set()

can you give an example with parameters?

It would be something like this:
Config::set('excel.import.startRow', $headerRowNumber);
Probably, you will have to add the Config class to get this working by adding use Config; to your file too.

L4.2 docs about "Configuration" mention these only and works with L5 too.

You can actually call LaravelExcelReader's method setHeaderRow(). According to my tests you have to call it before loading your xlsx file.

Example:
$reader->setHeaderRow(3); $reader->load('myfile.xlsx');

Please note that if you chunk-read the file the column mapping will fail.

hey, I have the same issue. I'm using chunk function and set startRow before load the file, but the start row always from row 1. here is my code:

\Config::set('excel.import.startRow', 2);
Excel::filter('chunk')
->load($dataSource)
->chunk(100, function($results) use ($log)

Hi nurwin, you can resolve? I have the same issue and i can't resolve it.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

daraghoshea picture daraghoshea  路  3Comments

rossjcooper picture rossjcooper  路  3Comments

disto picture disto  路  3Comments

lucatamtam picture lucatamtam  路  3Comments

thearabbit picture thearabbit  路  3Comments