0

I want to get excel sheet title.
I have method controller like this:

use Maatwebsite\Excel\Facades\Excel;



public function importCSVEXCEl()
   {

    Excel::load('test.xls', function($reader) {
        foreach($reader as $sheet)
        {

         $temp= $sheet->getTitle();
        }
    });
}

after execute this method show me error

Call to undefined method PHPExcel::getTitle()

1 Answer 1

2

According to Issue #316 discussion on Github:

If you have only one sheet, then you don't have to loop through the sheets.

Excel::load(public_path().$destinationPath.'/'.$name, function($sheet)
{
      // reader methods
      $sheetTitle = $sheet->getTitle();  
}); 

To verify the injected value in the closure is indeed a Sheet, you can dump it and see if the class is called "RowCollection".

If you always want to loop through the sheets no matter what, you'll have to set the import.force_sheets_collection to true.

and second suggestion from the same source:

This is what I used and seems to work

 $sheetNames = Excel::load($file)->getSheetNames();
Sign up to request clarification or add additional context in comments.

2 Comments

How can change import.force_sheets_collection. witch file should I change?
@paranoid This setting is in import section of excel.php file in your Laravel config folder.

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.