Issue
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()
Solution
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();
Answered By - KazikM Answer Checked By - Dawn Plyler (PHPFixing Volunteer)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.