在导入时按名称读取特定 sheet excel laravel
Read specific sheet by name on import excel laravel
我有一个 excel 有多个 sheet,但我只想读一个 sheet:
我的问题是我有多个 sheet,它们没有相同的顺序或相同的页数。然后,我必须在我的导入 class (laravel import).
中按名称识别 sheet
这是我的导入 class:
use Maatwebsite\Excel\Concerns\WithMultipleSheets;
use Maatwebsite\Excel\Concerns\WithEvents;
class ExecutedUPS implements WithMultipleSheets, WithEvents
{
private $nameSheetUPS = "LMS - F";
public function sheets(): array
{
$sheets = [];
//doesn't work for me
if($event->getSheet()->getTitle() === $this->nameSheetUPS){
$sheets[] = new SheetUPS();
}
return $sheets;
}
}
这是我的 class“SheetUPS”:
use Illuminate\Support\Collection;
use Maatwebsite\Excel\Concerns\ToCollection;
class SheetUPS implements ToCollection
{
/**
* @param Collection $collection
*/
public function collection(Collection $collection)
{
//this i know do
}
}
您是否尝试过像 documentation 那样按名称选择 sheet?
//class ExecutedUPS
public function sheets(): array
{
return [
'LMS - F' => new SheetUPS(),
];
}
我有一个 excel 有多个 sheet,但我只想读一个 sheet:
我的问题是我有多个 sheet,它们没有相同的顺序或相同的页数。然后,我必须在我的导入 class (laravel import).
中按名称识别 sheet这是我的导入 class:
use Maatwebsite\Excel\Concerns\WithMultipleSheets;
use Maatwebsite\Excel\Concerns\WithEvents;
class ExecutedUPS implements WithMultipleSheets, WithEvents
{
private $nameSheetUPS = "LMS - F";
public function sheets(): array
{
$sheets = [];
//doesn't work for me
if($event->getSheet()->getTitle() === $this->nameSheetUPS){
$sheets[] = new SheetUPS();
}
return $sheets;
}
}
这是我的 class“SheetUPS”:
use Illuminate\Support\Collection;
use Maatwebsite\Excel\Concerns\ToCollection;
class SheetUPS implements ToCollection
{
/**
* @param Collection $collection
*/
public function collection(Collection $collection)
{
//this i know do
}
}
您是否尝试过像 documentation 那样按名称选择 sheet?
//class ExecutedUPS
public function sheets(): array
{
return [
'LMS - F' => new SheetUPS(),
];
}