Skip to content

Commit

Permalink
Use computed value of formula cells (#342)
Browse files Browse the repository at this point in the history
  • Loading branch information
krenor authored Jan 11, 2024
1 parent 45f8cb6 commit 91743b3
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/Importable.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Illuminate\Support\Collection;
use Illuminate\Support\Str;
use OpenSpout\Common\Entity\Cell;
use OpenSpout\Reader\SheetInterface;
use OpenSpout\Writer\Common\AbstractOptions;

Expand Down Expand Up @@ -148,7 +149,13 @@ private function importSheet(SheetInterface $sheet, callable $callback = null)
$count_header = 0;

foreach ($sheet->getRowIterator() as $k => $rowAsObject) {
$row = $rowAsObject->toArray();
$row = array_map(function (Cell $cell) {
return match (true) {
$cell instanceof Cell\FormulaCell => $cell->getComputedValue(),
default => $cell->getValue(),
};
}, $rowAsObject->getCells());

if ($k >= $this->start_row) {
if ($this->with_header) {
if ($k == $this->start_row) {
Expand Down

0 comments on commit 91743b3

Please sign in to comment.