问题描述
我正在使用 Laravel 8 和 Laravel Excel 3.1 导入工作表,但无法访问当前的 Cell 对象及其超链接/URL。
解决方法
有解决办法!使用带有 <?php
//call your import script
config(['excel.imports.read_only' => false]); // to get access to all of the cells content
\Maatwebsite\Excel\Facades\Excel::import(new \App\Imports\Sheet1,$xlsFile);
接口的 Laravel Excel 导入模型:Handling persistence on your own 并编写更多代码
<?php
namespace App\Imports;
use Maatwebsite\Excel\Cell;
use Maatwebsite\Excel\Row;
use Maatwebsite\Excel\Concerns\OnEachRow;
class Sheet1 implements OnEachRow
{
public function onRow(Row $row)
{
foreach ($row->getDelegate()->getCellIterator() as $cell) {
$cellObj = new Cell($cell); //Laravel Facade Cell Object
$cellPHPOffice = $cellObj->getDelegate(); // PHP SpreadsheetCell object
if ($cellPHPOffice->hasHyperlink()) {
$url = $cellPHPOffice->->getHyperlink()->getUrl(); // Cell URL: works ONLY with excel.imports.read_only => false
}
}
}
}
Laravel Excel 导入类:
<div {...(condition && props)}></div>