Merge branch 'bugfix/invalid-cached-highest-column-after-column-removed' of https://github.com/darenas31415/PhpSpreadsheet
This commit is contained in:
commit
ddbd8ad0f5
|
@ -13,7 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org).
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
||||||
- ...
|
- Call garbage collector after removing a column to prevent stale cached values
|
||||||
|
|
||||||
## [1.9.0] - 2019-08-17
|
## [1.9.0] - 2019-08-17
|
||||||
|
|
||||||
|
|
|
@ -2154,6 +2154,7 @@ class Worksheet implements IComparable
|
||||||
$this->getCellCollection()->removeColumn($highestColumn);
|
$this->getCellCollection()->removeColumn($highestColumn);
|
||||||
$highestColumn = Coordinate::stringFromColumnIndex(Coordinate::columnIndexFromString($highestColumn) - 1);
|
$highestColumn = Coordinate::stringFromColumnIndex(Coordinate::columnIndexFromString($highestColumn) - 1);
|
||||||
}
|
}
|
||||||
|
$this->garbageCollect();
|
||||||
} else {
|
} else {
|
||||||
throw new Exception('Column references should not be numeric.');
|
throw new Exception('Column references should not be numeric.');
|
||||||
}
|
}
|
||||||
|
|
|
@ -181,4 +181,65 @@ class WorksheetTest extends TestCase
|
||||||
$worksheet->getCell('C1')->getValue()
|
$worksheet->getCell('C1')->getValue()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function removeColumnProvider(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'Remove first column' => [
|
||||||
|
[
|
||||||
|
['A1', 'B1', 'C1'],
|
||||||
|
['A2', 'B2', 'C2'],
|
||||||
|
],
|
||||||
|
'A',
|
||||||
|
[
|
||||||
|
['B1', 'C1'],
|
||||||
|
['B2', 'C2'],
|
||||||
|
],
|
||||||
|
'B',
|
||||||
|
],
|
||||||
|
'Remove middle column' => [
|
||||||
|
[
|
||||||
|
['A1', 'B1', 'C1'],
|
||||||
|
['A2', 'B2', 'C2'],
|
||||||
|
],
|
||||||
|
'B',
|
||||||
|
[
|
||||||
|
['A1', 'C1'],
|
||||||
|
['A2', 'C2'],
|
||||||
|
],
|
||||||
|
'B',
|
||||||
|
],
|
||||||
|
'Remove last column' => [
|
||||||
|
[
|
||||||
|
['A1', 'B1', 'C1'],
|
||||||
|
['A2', 'B2', 'C2'],
|
||||||
|
],
|
||||||
|
'C',
|
||||||
|
[
|
||||||
|
['A1', 'B1'],
|
||||||
|
['A2', 'B2'],
|
||||||
|
],
|
||||||
|
'B',
|
||||||
|
],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider removeColumnProvider
|
||||||
|
*/
|
||||||
|
public function testRemoveColumn(
|
||||||
|
array $initialData,
|
||||||
|
string $columnToBeRemoved,
|
||||||
|
array $expectedData,
|
||||||
|
string $expectedHighestColumn
|
||||||
|
) {
|
||||||
|
$spreadsheet = new Spreadsheet();
|
||||||
|
$worksheet = $spreadsheet->getActiveSheet();
|
||||||
|
$worksheet->fromArray($initialData);
|
||||||
|
|
||||||
|
$worksheet->removeColumn($columnToBeRemoved);
|
||||||
|
|
||||||
|
self::assertSame($expectedHighestColumn, $worksheet->getHighestColumn());
|
||||||
|
self::assertSame($expectedData, $worksheet->toArray());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue