0

I'm working with Laravel 8 and Laravel Excel 3.1 on importing the sheet and there is no way to access to the current Cell object and its Hyperlink/URL there.

1 Answer 1

0

There is the solution! Use Laravel Excel Import-to-model with OnEachRow interface: Handling persistence on your own and code little bit more

<?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 Import 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
            }
        }
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.