Skip to content

Commit 5fe0a79

Browse files
AlexPravdinPowerKiKi
authored andcommitted
Fix incorrect cache clearance on row deletion
Fixes #868 Closes #871
1 parent 0b387e7 commit 5fe0a79

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ and this project adheres to [Semantic Versioning](https://semver.org).
2525
- Fix handling of named ranges referencing sheets with spaces or "!" in their title
2626
- Cover `getSheetByName()` with tests for name with quote and spaces - [#739](https://github.com/PHPOffice/PhpSpreadsheet/issues/739)
2727
- Best effort to support invalid colspan values in HTML reader - [878](https://github.com/PHPOffice/PhpSpreadsheet/pull/878)
28+
- Fixes incorrect rows deletion [#868](https://github.com/PHPOffice/PhpSpreadsheet/issues/868)
2829

2930
## [1.8.2] - 2019-07-08
3031

src/PhpSpreadsheet/Worksheet/Worksheet.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2115,6 +2115,10 @@ public function insertNewColumnBeforeByIndex($beforeColumnIndex, $pNumCols = 1)
21152115
public function removeRow($pRow, $pNumRows = 1)
21162116
{
21172117
if ($pRow >= 1) {
2118+
for ($r = 0; $r < $pNumRows; ++$r) {
2119+
$this->getCellCollection()->removeRow($pRow + $r);
2120+
}
2121+
21182122
$highestRow = $this->getHighestDataRow();
21192123
$objReferenceHelper = ReferenceHelper::getInstance();
21202124
$objReferenceHelper->insertNewBefore('A' . ($pRow + $pNumRows), 0, -$pNumRows, $this);

tests/PhpSpreadsheetTests/Worksheet/WorksheetTest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,4 +161,24 @@ public function testExtractSheetTitle($range, $expectTitle, $expectCell, $expect
161161
self::assertSame($expectTitle, $arRange[0]);
162162
self::assertSame($expectCell2, $arRange[1]);
163163
}
164+
165+
/**
166+
* Fix https://github.com/PHPOffice/PhpSpreadsheet/issues/868 when cells are not removed correctly
167+
* on row deletion.
168+
*/
169+
public function testRemoveCellsCorrectlyWhenRemovingRow()
170+
{
171+
$workbook = new Spreadsheet();
172+
$worksheet = $workbook->getActiveSheet();
173+
$worksheet->getCell('A2')->setValue('A2');
174+
$worksheet->getCell('C1')->setValue('C1');
175+
$worksheet->removeRow(1);
176+
$this->assertEquals(
177+
'A2',
178+
$worksheet->getCell('A1')->getValue()
179+
);
180+
$this->assertNull(
181+
$worksheet->getCell('C1')->getValue()
182+
);
183+
}
164184
}

0 commit comments

Comments
 (0)