PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, October 5, 2022

[FIXED] How to get excel sheet title in laravel 5.2

 October 05, 2022     excel, laravel, laravel-5.2, php, phpexcel     No comments   

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)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing