如何在laravel Maatwebsite excel中读取工作表名称

Vik*_*nvi 3 laravel maatwebsite-excel

我的 Excel 工作表中有多个工作表,我想获取当前处于活动状态的工作表的名称

Sat*_*wat 7

我认为$event->getSheet()->getTitle()应该工作。您也可以使用事件。

class HImport1 implements ToCollection, WithHeadingRow, WithEvents
{
    public $sheetNames;
    public $sheetData;

    public function __construct(){
        $this->sheetNames = [];
    $this->sheetData = [];
    }
    public function collection(Collection $collection)
    {
        $this->sheetData[] = $collection;
    }
    public function registerEvents(): array
    {
        return [
            BeforeSheet::class => function(BeforeSheet $event) {
                $this->sheetNames[] = $event->getSheet()->getTitle();
            } 
        ];
    }

}
Run Code Online (Sandbox Code Playgroud)