Fix issue #1364: Removing last row incorrect behavior #1365
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is:
Checklist:
Why this change is needed?
This PR fixes #1364 Removing last row incorrect behavior
Description:
$highestRow = $this->getHighestDataRow();
was calculated after$this->getCellCollection()->removeRow($pRow + $r);
- this is the root reason for incorrect rows removal because removing last row will change '$this->getHighestDataRow()' value, but removing row from the middle will not change it. So, removing last row causes incorrect$highestRow
value that is used for wiping out empty rows from the bottom of the table:To prevent this incorrect behavior I've moved highest row calculation before row removal.
But this still doesn't solve another problem when trying remove non existing rows: in this case the code above will remove
$pNumRows
rows from below of the table, e.g. if$highestRow=4
and$pNumRows=6
, than rows 4, 3, 2, 1, 0, -1 will be deleted. Obviously, this is not good, that is why I've added$removedRowsCounter
to fix this issue.And finally, moved Exception to early if statement to get away from unnecessary 'if-else'.