如何获得excel表格标题在laravel 5.2

我想获得Excel表格标题。
我有像这样的方法控制器:

use Maatwebsite\Excel\Facades\Excel; public function importCSVEXCEl() { Excel::load('test.xls', function($reader) { foreach($reader as $sheet) { $temp= $sheet->getTitle(); } }); } 

执行这个方法后显示错误

调用未定义的方法PHPExcel :: getTitle()

根据关于Github的问题#316的讨论 :

如果你只有一张纸,那么你不必循环纸张。

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

要validation闭包中的注入值确实是一个Sheet,可以将其转储,并查看该类是否被称为“RowCollection”。

如果你总是想循环遍历表,无论如何,你必须将import.force_sheets_collection设置为true。

并从同一来源的第二个build议:

这是我使用,似乎工作

  $sheetNames = Excel::load($file)->getSheetNames();