Laravel Excel 使用 URL 获取导入单元格访问权限

Laravel Excel get importing cell access with URL

我正在与 Laravel 8 and Laravel Excel 3.1 合作导入 sheet,但无法访问当前 Cell 对象及其 Hyperlink/URL。

有解决办法!使用 Laravel Excel 导入模型与 OnEachRow 接口:Handling persistence on your own 和代码多一点

<?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 导入 class:

<?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
            }
        }
    }
}