Hi, I have a excel file with 9 sheet's. Have a way to specify a sheet to import? I need only the first sheet, I don't found in documentation (except 2.1) a way to specify this.
Edit: I found this:
$import->onlySheets('worksheet 1');
But I'm not have the name of the sheet I need to import. Have a way to specify the '0'|'1' sheet?
Have you tried Selecting sheets by worksheet index?
I think onlySheets only works with sheet names and not with index.
I can make the reference to same class to not make a new class?
I can make the reference to same class to not make a new class?
You could try, but not sure if that would actually work. To be safe, I'd use two separate classes.
From the docs:
When a file has multiple sheets, each sheet will go through the import object. If you want to handle each sheet separately, you'll need to implement the WithMultipleSheets concern.
I found here: https://github.com/Maatwebsite/Laravel-Excel/issues/2017
class EventsImport implements ToCollection, WithMultipleSheets
{
.....
/**
* @return array
*/
public function sheets(): array
{
return [
0 => $this,
];
}
}
But, now cells with formula has comming with formula value, not the 'value' of the result. Have any idea?
Edit: The time to load the sheet is the same, using or not only first sheet inside.
See our list of Import concerns. There's a WithCalculatedFormulas concern.
See our list of Import concerns. There's a
WithCalculatedFormulasconcern.
Works, where's the result for reference:
class EventsImport implements ToCollection , WithMultipleSheets, WithCalculatedFormulas
{
.....
/**
* @return array
*/
public function sheets(): array
{
return [
0 => $this,
];
}
/**
* @param Collection $collection
* @throws \Exception
*/
public function collection(Collection $collection)
{
......
}
}
Glad to hear your issue has been resolved. Thank you for using Laravel Excel!
@kidjapa worked perfectly. but what if i just want to get data from 2nd sheet
Most helpful comment
I found here: https://github.com/Maatwebsite/Laravel-Excel/issues/2017