问题
I am trying to import an excel file using maatwebsite's laravel excel package 2.0.8 for Laravel 5.2. I would like to be able to change the startRow inside my controller instead of inside the config so it doesn't affect everyone.
public function import()
{
$results = Excel::load('doctors.csv', function($reader) {
})->get();
}
回答1:
You can try this before reading the file:
config(['excel.import.startRow' = rowNumber]);
It worked for me.
Source: https://github.com/Maatwebsite/Laravel-Excel/issues/886
回答2:
You could use the skip() or limit() method:
$results = Excel::load('doctors.csv', function($reader) {})
->skip(1) // Skip one row
->get();
// Or, with limit:
$results = Excel::load('doctors.csv', function($reader) {})
->limit(false, 1) // Skip one row
->get();
回答3:
Config::set('excel.import.startRow', $rowNumber);
$rowNumber is a number of rows that you want to start import data from your file. Make sure you put this function before you read your file.
来源:https://stackoverflow.com/questions/38274521/how-do-i-change-startrow-for-maatwebsites-laravel-excel-package-2-0-8-for-larav