Fix incorrect cache clearance on row deletion

Fixes #868
Closes #871
This commit is contained in:
Alex Pravdin 2019-01-31 19:38:31 +09:00 committed by Adrien Crivelli
parent 0b387e767e
commit 5fe0a796c7
No known key found for this signature in database
GPG Key ID: B182FD79DC6DE92E
3 changed files with 25 additions and 0 deletions

View File

@ -25,6 +25,7 @@ and this project adheres to [Semantic Versioning](https://semver.org).
- Fix handling of named ranges referencing sheets with spaces or "!" in their title
- Cover `getSheetByName()` with tests for name with quote and spaces - [#739](https://github.com/PHPOffice/PhpSpreadsheet/issues/739)
- Best effort to support invalid colspan values in HTML reader - [878](https://github.com/PHPOffice/PhpSpreadsheet/pull/878)
- Fixes incorrect rows deletion [#868](https://github.com/PHPOffice/PhpSpreadsheet/issues/868)
## [1.8.2] - 2019-07-08

View File

@ -2115,6 +2115,10 @@ class Worksheet implements IComparable
public function removeRow($pRow, $pNumRows = 1)
{
if ($pRow >= 1) {
for ($r = 0; $r < $pNumRows; ++$r) {
$this->getCellCollection()->removeRow($pRow + $r);
}
$highestRow = $this->getHighestDataRow();
$objReferenceHelper = ReferenceHelper::getInstance();
$objReferenceHelper->insertNewBefore('A' . ($pRow + $pNumRows), 0, -$pNumRows, $this);

View File

@ -161,4 +161,24 @@ class WorksheetTest extends TestCase
self::assertSame($expectTitle, $arRange[0]);
self::assertSame($expectCell2, $arRange[1]);
}
/**
* Fix https://github.com/PHPOffice/PhpSpreadsheet/issues/868 when cells are not removed correctly
* on row deletion.
*/
public function testRemoveCellsCorrectlyWhenRemovingRow()
{
$workbook = new Spreadsheet();
$worksheet = $workbook->getActiveSheet();
$worksheet->getCell('A2')->setValue('A2');
$worksheet->getCell('C1')->setValue('C1');
$worksheet->removeRow(1);
$this->assertEquals(
'A2',
$worksheet->getCell('A1')->getValue()
);
$this->assertNull(
$worksheet->getCell('C1')->getValue()
);
}
}