1

I'm trying to import excel files but it always give me this error:

PHPExcel_Exception
Row 2 is out of range (2 - 1)

I'm using Laravel 4 and here's my code:

public function postExcel()
{
    $file = Input::file('file');

    $destinationPath = public_path() .'/uploads/temp/';
    $filename   = str_replace(' ', '_', $file->getClientOriginalName());
    $file->move($destinationPath, $filename);

    $result = Excel::selectSheets('Sheet1')->load($destinationPath)->get();

    echo "<pre>";
    var_dump($result->toArray());
    exit;

}

This is my dummy excel file: dummy excel

I've tried to google this but for other it seems like it only occurs when the sheet is more than one, but it's not like that in my case.

6
  • What line causes the error? Commented Jul 15, 2015 at 3:32
  • 1
    Also, you appear to be load()ing the public/uploads/temp folder, not the individual file. Commented Jul 15, 2015 at 3:36
  • the $result = Excel::selectSheets('Sheet1')->load($destinationPath)->get(); line... when I change it to: $result = Excel::selectSheetsByIndex(0)->load($destinationPath, function($reader) { $reader->noHeading(); })->get(); it gives no error but it returns null array... is it the excel file problem? Commented Jul 15, 2015 at 3:37
  • 1
    I'm not familiar with the library, but it seems weird to selectSheets() before you load() the file, and I'd guess you should be doing load($destinationPath . $filename) for starters. Commented Jul 15, 2015 at 3:39
  • Oh my bad! sorry, i forgot to add the filename, now it works! thanks a bunch! Commented Jul 15, 2015 at 3:40

1 Answer 1

1

You need to load($destinationPath . $filename), not load($destinationPath) - the directory isn't an Excel file. :-)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.