Skip to content

Commit a8d9cd7

Browse files
author
MarkBaker
committed
Allow deleting of columns beyond the end of data in a worksheet to update references (print area, etc) before early exiting the method
1 parent 092f902 commit a8d9cd7

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/PhpSpreadsheet/Worksheet/Worksheet.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2219,25 +2219,25 @@ public function removeColumn($column, $numberOfColumns = 1)
22192219
$highestColumnIndex = Coordinate::columnIndexFromString($highestColumn);
22202220
$pColumnIndex = Coordinate::columnIndexFromString($column);
22212221

2222-
if ($pColumnIndex > $highestColumnIndex) {
2223-
return $this;
2224-
}
2225-
22262222
$holdColumnDimensions = $this->removeColumnDimensions($pColumnIndex, $numberOfColumns);
22272223

22282224
$column = Coordinate::stringFromColumnIndex($pColumnIndex + $numberOfColumns);
22292225
$objReferenceHelper = ReferenceHelper::getInstance();
22302226
$objReferenceHelper->insertNewBefore($column . '1', -$numberOfColumns, 0, $this);
22312227

2228+
$this->columnDimensions = $holdColumnDimensions;
2229+
2230+
if ($pColumnIndex > $highestColumnIndex) {
2231+
return $this;
2232+
}
2233+
22322234
$maxPossibleColumnsToBeRemoved = $highestColumnIndex - $pColumnIndex + 1;
22332235

22342236
for ($c = 0, $n = min($maxPossibleColumnsToBeRemoved, $numberOfColumns); $c < $n; ++$c) {
22352237
$this->getCellCollection()->removeColumn($highestColumn);
22362238
$highestColumn = Coordinate::stringFromColumnIndex(Coordinate::columnIndexFromString($highestColumn) - 1);
22372239
}
22382240

2239-
$this->columnDimensions = $holdColumnDimensions;
2240-
22412241
$this->garbageCollect();
22422242

22432243
return $this;

0 commit comments

Comments
 (0)