From 91743b3bbf6a7d74cab0f21040c80949e9af885e Mon Sep 17 00:00:00 2001 From: Stan Date: Thu, 11 Jan 2024 17:28:58 +0100 Subject: [PATCH] Use computed value of formula cells (#342) Introduced by https://github.com/openspout/openspout/pull/169 --- src/Importable.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Importable.php b/src/Importable.php index fab9511..ae5612d 100644 --- a/src/Importable.php +++ b/src/Importable.php @@ -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; @@ -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) {