php - Laravel Excel import multi sheets not work - Stack Overflow

admin2025-04-25  4

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

Running

转载请注明原文地址:http://anycun.com/QandA/1745547224a90910.html