Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting Sheet Title Error #316

Closed
melvin0008 opened this issue Jan 15, 2015 · 7 comments
Closed

Getting Sheet Title Error #316

melvin0008 opened this issue Jan 15, 2015 · 7 comments

Comments

@melvin0008
Copy link

Excel::load(public_path().$destinationPath.'/'.$name, function($reader) {
          // reader methods
          $workbookTitle = $reader->getTitle();
          Log::info($workbookTitle);
          foreach($reader as $sheet)
            {
                // get sheet title
                 $sheetTitle = $sheet->getTitle();
                 Log::info($sheetTitle);
            }
        });

Getting an error for get title.

 production.ERROR: exception 'Symfony\Component\Debug\Exception\FatalErrorException' with message 'Call to undefined method PHPExcel::getTitle()' in

@melvin0008 melvin0008 changed the title Get Title Error Getting Sheet Title Error Jan 15, 2015
@vuchl
Copy link

vuchl commented Jan 15, 2015

Hmm strange. The method is there.

@melvin0008
Copy link
Author

Yup strange.
Is the error on this line
$this->excel->getProperties()->getTitle();

@melvin0008
Copy link
Author

This is weird PHPExcel does have a method called getTitle . Its here

melvin0008 added a commit to melvin0008/Laravel-Excel that referenced this issue Jan 16, 2015
SpartnerNL#316 I encountered an issue when I tried acquiring sheet name . So this workaround.
Thanks
@MaatwebsiteSupport
Copy link
Contributor

No need to add an extra method.
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.

@melvin0008
Copy link
Author

Thanks

@ericmuigai
Copy link

This is what I used and seems to work
$sheetNames = Excel::load($file)->getSheetNames();
Hope it helps :)

@flosej
Copy link

flosej commented Nov 17, 2017

That works

foreach($reader->all() as $sheet) { // get sheet title $sheetTitle = $sheet->getTitle(); dd($sheetTitle); }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants