【问题标题】:Read specific sheet by name on import excel laravel在导入 excel laravel 上按名称读取特定工作表
【发布时间】:2021-12-12 17:48:59
【问题描述】:

我有一个包含多张工作表的 Excel,但我只想阅读一张工作表:

我的问题是我有多张纸,它们没有相同的顺序或相同的页数。然后,我必须在我的导入类 (laravel import) 上按名称识别工作表。

这是我的导入类:

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;
    }
}

这是我的课“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
    }
}

【问题讨论】:

    标签: excel laravel file-upload import laravel-excel


    【解决方案1】:

    您是否尝试过像 documentation 那样按名称选择工作表?

    //class ExecutedUPS
    public function sheets(): array
    {
        return [
            'LMS - F' => new SheetUPS(),
        ];
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-02-09
      • 2013-08-27
      • 2016-02-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多