I am using the Laravel Excel library and I have been reading the documentation but it does not say anything to read the excel from a certain row number, that is, I have the first 6 lines of the excel with information and the "title" of each column It is not until row 7, how do I indicate to the function that the "indexes" are there?
public function excel($id){
$bankFiles = FicheroBanco::find($id);
$url = $bankFiles->url;
Excel::selectSheetsByIndex(0)->load($url, function ($sheet){
//$sheet->noHeading();
$sheet->each(function ($row){
$mov = new Transaccion();
$mov->cuenta = $row->cuenta;
$mov->divisa = $row->divisa;
$mov->titular = $row->titular;
$mov->fecha = $row->fecha;
$mov->concepto = $row->concepto;
$mov->valor = $row->valor;
$mov->importe = $row->importe;
$mov->saldo = $row->saldo;
$mov->observaciones = $row->observaciones;
$mov->extra = $row->extra;
$mov->save();
});
});
return view('bank.excel');
}
I have seen that I can use the ->take(); to grab the first x lines of a document or the ->skip(); to skip the first x lines. The problem is that the first line of the excel file is a merged cell of 7 columns, I cannot use the titles of line 6, since it mounts the unstructured array.
EDIT: By default it can be configured from within the excel.php configuration file in the field 'startRow' => 1 but the thing is that I can't get any type of information from the fields before that line either. The thing is that I need the info of some fields of the first 6 lines, but I need to indicate that the headings start at line 6. Any ideas?
I have read in the documentation that the parameter ->byConfig(); but as indicated only in case of not using headings.
Could someone tell me how to do it?
I need to insert the fields before the "headings" into the database, for each subsequent row of data.
EDIT: I have been doing tests and although I do two different functions, one without using headings and the other if, having changed the startRow parameter of the configuration, both one and the other load me from the same row. I don't know how to tell one to load from a row and the other to load from the beginning. It can?
The above code works perfectly for me if I put 'startRow' => 6 , instead if I use noheadings (with startrow 6) I can't access previous rows of the excel file.
I cannot modify the structure of the excel since I must stick to it.
I leave the documentation -> http://www.maatwebsite.nl/laravel-excel/docs
In the end, the solution has been to leave the excel.php configuration as it was, that is, 'startRow' => 1 to be able to access all the tuples from the beginning and I have done the following:
This way I was able to get what I wanted. The problem was that I didn't know how to traverse $sheet but later in the documentation I saw that there are ->toArray() and ->toObject() and that way it returns the object as it plays without strange positions and for each of a lifetime or whatever it takes.
I hope it is useful for someone.