diff --git a/src/PhpSpreadsheet/Worksheet/ColumnCellIterator.php b/src/PhpSpreadsheet/Worksheet/ColumnCellIterator.php index 9d0be5bd..2db4da37 100644 --- a/src/PhpSpreadsheet/Worksheet/ColumnCellIterator.php +++ b/src/PhpSpreadsheet/Worksheet/ColumnCellIterator.php @@ -120,7 +120,11 @@ class ColumnCellIterator extends CellIterator */ public function current(): ?Cell { - return $this->worksheet->getCellByColumnAndRow($this->columnIndex, $this->currentRow); + $cellAddress = Coordinate::stringFromColumnIndex($this->columnIndex) . $this->currentRow; + + return $this->worksheet->getCellCollection()->has($cellAddress) + ? $this->worksheet->getCellCollection()->get($cellAddress) + : $this->worksheet->createNewCell($cellAddress); } /** diff --git a/src/PhpSpreadsheet/Worksheet/RowCellIterator.php b/src/PhpSpreadsheet/Worksheet/RowCellIterator.php index a78765bd..72c0c9c1 100644 --- a/src/PhpSpreadsheet/Worksheet/RowCellIterator.php +++ b/src/PhpSpreadsheet/Worksheet/RowCellIterator.php @@ -123,7 +123,11 @@ class RowCellIterator extends CellIterator */ public function current(): ?Cell { - return $this->worksheet->getCellByColumnAndRow($this->currentColumnIndex, $this->rowIndex); + $cellAddress = Coordinate::stringFromColumnIndex($this->currentColumnIndex) . $this->rowIndex; + + return $this->worksheet->getCellCollection()->has($cellAddress) + ? $this->worksheet->getCellCollection()->get($cellAddress) + : $this->worksheet->createNewCell($cellAddress); } /**