Skip to content

Commit 7201ddd

Browse files
author
MarkBaker
committed
Update get cell logic in Cell Iterators
1 parent 4a071ce commit 7201ddd

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

src/PhpSpreadsheet/Worksheet/ColumnCellIterator.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,11 @@ public function rewind(): void
120120
*/
121121
public function current(): ?Cell
122122
{
123-
return $this->worksheet->getCellByColumnAndRow($this->columnIndex, $this->currentRow);
123+
$cellAddress = Coordinate::stringFromColumnIndex($this->columnIndex) . $this->currentRow;
124+
125+
return $this->worksheet->getCellCollection()->has($cellAddress)
126+
? $this->worksheet->getCellCollection()->get($cellAddress)
127+
: $this->worksheet->createNewCell($cellAddress);
124128
}
125129

126130
/**

src/PhpSpreadsheet/Worksheet/RowCellIterator.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,11 @@ public function rewind(): void
123123
*/
124124
public function current(): ?Cell
125125
{
126-
return $this->worksheet->getCellByColumnAndRow($this->currentColumnIndex, $this->rowIndex);
126+
$cellAddress = Coordinate::stringFromColumnIndex($this->currentColumnIndex) . $this->rowIndex;
127+
128+
return $this->worksheet->getCellCollection()->has($cellAddress)
129+
? $this->worksheet->getCellCollection()->get($cellAddress)
130+
: $this->worksheet->createNewCell($cellAddress);
127131
}
128132

129133
/**

0 commit comments

Comments
 (0)