Laravel-excel: v3.1.* 版本未实现 WithMultipleSheets ,但同时实现 WithHeadingRow 时,导入会出现报错 Start row (2) is beyond highest row (1)

Created on 7 Oct 2018  ·  15Comments  ·  Source: Maatwebsite/Laravel-Excel

这是我使用的 xlsx

test.xlsx

当我在 import 中 implement WithHeadingRow 时,会抛出错误 Start row (2) is beyond highest row (1)

这个 test.xlsx 有 3 个 sheet ,实际在使用的只有第一个 sheet

image

image

这会导致 $sheet->getStartRow($sheetImport) 在空的 sheet 中进行 import 操作。

所以抛出了这个错误

more information needed

Most helpful comment

the problem is this

image

the answer solve my problem.

You should use the WithMultipleSheets in that case.

namespace App\Imports;

use Maatwebsite\Excel\Concerns\WithMultipleSheets;

class UsersImport implements WithMultipleSheets {

    public function sheets(): array
    {
        return [
            // Select by sheet index
            0 => new FirstSheetImport(),
        ];
    }
}

https://laravel-excel.maatwebsite.nl/3.1/imports/multiple-sheets.html

just do that.

image

thank you, @patrickbrouwers

All 15 comments

Thanks for submitting the ticket. Unfortunately the information you provided is incomplete. We need to know which version you use and how to reproduce it. Please include code examples. Before we can pick it up, please check (https://github.com/Maatwebsite/Laravel-Excel/blob/3.0/.github/ISSUE_TEMPLATE.md) and add the missing information. To make processing of this ticket a lot easier, please make sure to check (https://laravel-excel.maatwebsite.nl/docs/3.0/getting-started/contributing) and double-check if you have filled in the issue template correctly. This will allow us to pick up your ticket more efficiently. Issues that follow the guidelines correctly will get priority over other issues.

image

这样可以解决, 但是不知道是否有更好的解决方案

Please translate to English.

I just want to use the first sheet to import. But sheet has 3, and 2 are empty. how can i Specify the imported sheet ? @patrickbrouwers @GlennM

You should use the WithMultipleSheets in that case.

namespace App\Imports;

use Maatwebsite\Excel\Concerns\WithMultipleSheets;

class UsersImport implements WithMultipleSheets {

    public function sheets(): array
    {
        return [
            // Select by sheet index
            0 => new FirstSheetImport(),
        ];
    }
}

https://laravel-excel.maatwebsite.nl/3.1/imports/multiple-sheets.html

the problem is this

image

the answer solve my problem.

You should use the WithMultipleSheets in that case.

namespace App\Imports;

use Maatwebsite\Excel\Concerns\WithMultipleSheets;

class UsersImport implements WithMultipleSheets {

    public function sheets(): array
    {
        return [
            // Select by sheet index
            0 => new FirstSheetImport(),
        ];
    }
}

https://laravel-excel.maatwebsite.nl/3.1/imports/multiple-sheets.html

just do that.

image

thank you, @patrickbrouwers

how can i specify the imported sheet if i use v2.* ?

just do that. when using v2.* version.

image

Version 2.* is no longer supported.

Version 2.* is no longer supported.

yes . but this is old project.

You'll have to upgrade to 3.1 or use it on own risk. We can no longer support this outdated version which uses abandoned software (PHPExcel).

OK, thank you for your answer. @patrickbrouwers

Looks like collection() method doesn't work with WithMultipleSheets, because I didn't get "test" in the output. Is it right behavior? Or I do something wrong?

class ClientsImport implements ToCollection, WithHeadingRow, WithMultipleSheets
{
    public function sheets(): array
    {
        return [
            0 => new static
        ];
    }

    public function collection(Collection $rows)
    {
        echo 'test';
        exit;
    }

Version 2.* is no longer supported.

You'll have to upgrade to 3.1 or use it on own risk. We can no longer support this outdated version which uses abandoned software (PHPExcel).

Sir how can I implement the WithStartRow interface? I have an excel file with columns starting at row 5, now when I try to use the startRow function, it says Undefined index: Firtsname (my first column). Can you help me solve this issue. need to resolve this ASAP. Thanks in advance

Version 2.* is no longer supported.

You'll have to upgrade to 3.1 or use it on own risk. We can no longer support this outdated version which uses abandoned software (PHPExcel).

Sir how can I implement the WithStartRow interface? I have an excel file with columns starting at row 5, now when I try to use the startRow function, it says Undefined index: Firtsname (my first column). Can you help me solve this issue. need to resolve this ASAP. Thanks in advance

Could you open a new issue if needed according to the template, instead of replying to an older ticket, including some code?

Please check if you're using WithHeadingRow. In that case, you can use the column names.

Was this page helpful?
0 / 5 - 0 ratings