如何在 laravel 5.2 中获得 excel sheet 标题
How to get excel sheet title in laravel 5.2
我想获得excelsheet称号。
我有这样的方法控制器:
use Maatwebsite\Excel\Facades\Excel;
public function importCSVEXCEl()
{
Excel::load('test.xls', function($reader) {
foreach($reader as $sheet)
{
$temp= $sheet->getTitle();
}
});
}
执行此方法后显示错误
Call to undefined method PHPExcel::getTitle()
根据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.
来自同一来源的第二个建议:
This is what I used and seems to work
$sheetNames = Excel::load($file)->getSheetNames();
我想获得excelsheet称号。
我有这样的方法控制器:
use Maatwebsite\Excel\Facades\Excel;
public function importCSVEXCEl()
{
Excel::load('test.xls', function($reader) {
foreach($reader as $sheet)
{
$temp= $sheet->getTitle();
}
});
}
执行此方法后显示错误
Call to undefined method PHPExcel::getTitle()
根据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.
来自同一来源的第二个建议:
This is what I used and seems to work
$sheetNames = Excel::load($file)->getSheetNames();