WeiCheng
WeiCheng

Reputation: 37

Laravel Excel import multi sheets not work

version

PHP - 7.4.33

Laravel - 6.20.44

maatwebsite/excel - 3.1.56

Description

I have tried to use WithMultipleSheets to import multi sheets from a excel, but it just use the first Import ZoneRuleImport to all the sheet data. Is anything wrong?

Code

$import = new CarrierPriceRuleImport($ruleId, $length);

Excel::import($import, $file);
class CarrierPriceRuleImport implements WithMultipleSheets, SkipsUnknownSheets
{
    protected $ruleId, $length;

    public function __construct($ruleId, $length = 5)
    {
        $this->ruleId = $ruleId;
        $this->length = $length;
    }

    public function sheets(): array
    {
        return [
            0 => new ZoneRuleImport($this->ruleId, $this->length),
            1 => new ZonePriceImport($this->ruleId),
        ];
    }

    public function onUnknownSheet($sheetName)
    {
        dump($sheetName);
    }
}

Excel

enter image description here

Running

enter image description here

Upvotes: 1

Views: 37

Answers (0)

Related Questions