Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
bc8dd75030
|
@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org).
|
|||
### Fixed
|
||||
|
||||
- Call garbage collector after removing a column to prevent stale cached values
|
||||
- Trying to remove a column that doesn't exist deletes the latest column
|
||||
|
||||
## [1.9.0] - 2019-08-17
|
||||
|
||||
|
|
|
@ -2145,19 +2145,30 @@ class Worksheet implements IComparable
|
|||
*/
|
||||
public function removeColumn($pColumn, $pNumCols = 1)
|
||||
{
|
||||
if (!is_numeric($pColumn)) {
|
||||
if (is_numeric($pColumn)) {
|
||||
throw new Exception('Column references should not be numeric.');
|
||||
}
|
||||
|
||||
$highestColumn = $this->getHighestDataColumn();
|
||||
$pColumn = Coordinate::stringFromColumnIndex(Coordinate::columnIndexFromString($pColumn) + $pNumCols);
|
||||
$highestColumnIndex = Coordinate::columnIndexFromString($highestColumn);
|
||||
$pColumnIndex = Coordinate::columnIndexFromString($pColumn);
|
||||
|
||||
if ($pColumnIndex > $highestColumnIndex) {
|
||||
return $this;
|
||||
}
|
||||
|
||||
$pColumn = Coordinate::stringFromColumnIndex($pColumnIndex + $pNumCols);
|
||||
$objReferenceHelper = ReferenceHelper::getInstance();
|
||||
$objReferenceHelper->insertNewBefore($pColumn . '1', -$pNumCols, 0, $this);
|
||||
for ($c = 0; $c < $pNumCols; ++$c) {
|
||||
|
||||
$maxPossibleColumnsToBeRemoved = $highestColumnIndex - $pColumnIndex + 1;
|
||||
|
||||
for ($c = 0, $n = min($maxPossibleColumnsToBeRemoved, $pNumCols); $c < $n; ++$c) {
|
||||
$this->getCellCollection()->removeColumn($highestColumn);
|
||||
$highestColumn = Coordinate::stringFromColumnIndex(Coordinate::columnIndexFromString($highestColumn) - 1);
|
||||
}
|
||||
|
||||
$this->garbageCollect();
|
||||
} else {
|
||||
throw new Exception('Column references should not be numeric.');
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
|
|
@ -191,6 +191,7 @@ class WorksheetTest extends TestCase
|
|||
['A2', 'B2', 'C2'],
|
||||
],
|
||||
'A',
|
||||
1,
|
||||
[
|
||||
['B1', 'C1'],
|
||||
['B2', 'C2'],
|
||||
|
@ -203,6 +204,7 @@ class WorksheetTest extends TestCase
|
|||
['A2', 'B2', 'C2'],
|
||||
],
|
||||
'B',
|
||||
1,
|
||||
[
|
||||
['A1', 'C1'],
|
||||
['A2', 'C2'],
|
||||
|
@ -215,12 +217,39 @@ class WorksheetTest extends TestCase
|
|||
['A2', 'B2', 'C2'],
|
||||
],
|
||||
'C',
|
||||
1,
|
||||
[
|
||||
['A1', 'B1'],
|
||||
['A2', 'B2'],
|
||||
],
|
||||
'B',
|
||||
],
|
||||
'Remove a column out of range' => [
|
||||
[
|
||||
['A1', 'B1', 'C1'],
|
||||
['A2', 'B2', 'C2'],
|
||||
],
|
||||
'D',
|
||||
1,
|
||||
[
|
||||
['A1', 'B1', 'C1'],
|
||||
['A2', 'B2', 'C2'],
|
||||
],
|
||||
'C',
|
||||
],
|
||||
'Remove multiple columns' => [
|
||||
[
|
||||
['A1', 'B1', 'C1'],
|
||||
['A2', 'B2', 'C2'],
|
||||
],
|
||||
'B',
|
||||
5,
|
||||
[
|
||||
['A1'],
|
||||
['A2'],
|
||||
],
|
||||
'A',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -230,6 +259,7 @@ class WorksheetTest extends TestCase
|
|||
public function testRemoveColumn(
|
||||
array $initialData,
|
||||
string $columnToBeRemoved,
|
||||
int $columnsToBeRemoved,
|
||||
array $expectedData,
|
||||
string $expectedHighestColumn
|
||||
) {
|
||||
|
@ -237,7 +267,7 @@ class WorksheetTest extends TestCase
|
|||
$worksheet = $spreadsheet->getActiveSheet();
|
||||
$worksheet->fromArray($initialData);
|
||||
|
||||
$worksheet->removeColumn($columnToBeRemoved);
|
||||
$worksheet->removeColumn($columnToBeRemoved, $columnsToBeRemoved);
|
||||
|
||||
self::assertSame($expectedHighestColumn, $worksheet->getHighestColumn());
|
||||
self::assertSame($expectedData, $worksheet->toArray());
|
||||
|
|
Loading…
Reference in New Issue