0

I am using Laravel Excel 2.1. I have an array of data that I want to add as a new sheet to an existing excel file and save it locally.

Here is the code I am trying

Excel::load(base_path() . '/storage/app/surveyFilters/' . $surveyFilter->filename, function($file) use($data) {
    $file->sheet('Individuals - Tagged', function($sheet) use($data)
    {
        $sheet->fromArray($data);
    });

})->store('xls', public_path('assets')); 

I get this error "Call to a member function fromArray() on null". If I var_dump $data right before the call and exit it shows my array so $data is not null. I also tried with() instead of fromArray() but get similar error message.

Any help would be appreciated.

Chris
  • 486
  • 3
  • 8
  • 22
  • The error message is saying `$sheet` is null, not `$data` – Derek Pollard Mar 28 '19 at 17:57
  • You are correct. $sheet is null. Any idea why $sheet is null? If I comment out $sheet->fromArray($data); it runs fine and puts adds the excel file to the path I give it so it loads the file fine. – Chris Mar 28 '19 at 18:13
  • From reading the documentation, it appears as though you're trying to add a sheet on an already created file, whereas the documentation only shows that you can do that from a newly created instance from `Excel::create()` – Derek Pollard Mar 28 '19 at 18:19
  • Thanks. That would explain it as that is what i am trying to do. – Chris Mar 28 '19 at 18:27

0 Answers0