Laravel-excel: Undefined offset 1

Created on 24 Oct 2018  Â·  9Comments  Â·  Source: Maatwebsite/Laravel-Excel

Prerequisites

  • [X] Able to reproduce the behaviour outside of your code, the problem is isolated to Laravel Excel.
  • [X] Checked that your issue isn't already filed.
  • [X] Checked if no PR was submitted that fixes this problem.

Versions

  • PHP version: 7.2.10
  • Laravel version: 5.7.9
  • Package version: 3.1

Description

I am just trying to learn this package and I am a simple model Team. Trying to import and export data from this model, this has exactly two fields name and description. When I am trying to import the teams.xlsx, it is showing error

Undefined offset: 1

Steps to Reproduce

I have followed this doc only difference is fields are name and description.

model method in my TeamsImport is

public function model(array $row)
    {
        //dd( $row[1] );
        return new Team([
            'name' => $row[0],
            'description' => $row[1]
        ]);
    }


        return redirect('/')->with('failed', 'Some thing gone wrong!');
    }

Expected behavior:

I think it should upload the file .

Actual behavior:

I have not idea, why it is getting undefined offset 1. while I am getting 'descripption' for dd($row[1]).

Additional Information

Any additional information, configuration or data that might be necessary to reproduce the issue.
This is the xls file, I am trying to import.
teams.xlsx

Most helpful comment

Either by removing the 2 extra sheets from your file, or by following the documentation of multiple sheets: https://laravel-excel.maatwebsite.nl/3.1/imports/multiple-sheets.html

All 9 comments

Try dump($row) and see what each row contains. It's probably not the first row, as dd() works for you.

I am getting the data inserted to my table correctly.But still getting this error. If I am using dump($row) I am getting output

array:2 [â–¼
  0 => "name"
  1 => "decription"
]

Perhaps it is because you have 3 sheets, and you get the error on the 2nd sheet.

@patrickbrouwers thank you, but Can you please suggest me some idea, how I should handle it?

Either by removing the 2 extra sheets from your file, or by following the documentation of multiple sheets: https://laravel-excel.maatwebsite.nl/3.1/imports/multiple-sheets.html

Got it correct, thank you so much.

Great :)

Either by removing the 2 extra sheets from your file, or by following the documentation of multiple sheets: https://laravel-excel.maatwebsite.nl/3.1/imports/multiple-sheets.html

thank you, this is really help me

Either by removing the 2 extra sheets from your file, or by following the documentation of multiple sheets: https://laravel-excel.maatwebsite.nl/3.1/imports/multiple-sheets.html

I hope I'd have found this answer sooner. You're a genius! It worked!

Was this page helpful?
0 / 5 - 0 ratings