How do I change startRow for maatwebsite's laravel excel package 2.0.8 for Laravel 5.2 somewhere besides the excel.php config file?

与世无争的帅哥 提交于 2019-12-23 17:52:23

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!