Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue #1364: Removing last row incorrect behavior #1365

Merged
merged 6 commits into from
Apr 26, 2020
Merged

Fix issue #1364: Removing last row incorrect behavior #1365

merged 6 commits into from
Apr 26, 2020

Conversation

TimGa
Copy link
Contributor

@TimGa TimGa commented Feb 17, 2020

This is:

- [X] a bugfix
- [ ] a new feature

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:

for ($r = 0; $r < $pNumRows; ++$r) {
    $this->getCellCollection()->removeRow($highestRow);
    --$highestRow;
}

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'.

@TimGa
Copy link
Contributor Author

TimGa commented Mar 11, 2020

Hi, @PowerKiKi
Could you please review this PR?

@minhtranahri
Copy link

Hi @TimGa , i think just remove this code is enough

for ($r = 0; $r < $pNumRows; ++$r) {
    $this->getCellCollection()->removeRow($highestRow);
    --$highestRow;
}

@TimGa
Copy link
Contributor Author

TimGa commented Mar 31, 2020

Hi @minhtranahri , you are right, removing this part of code will solve the issue, but somebody wrote it for some reason, that is why I decided to keep it. This part of code could be used for deleting cache stuff or some other implicit actions i don't know. So I decided to fix this issue without removing existing lines of code.

@minhtranahri
Copy link

Hi @TimGa, thanks for clarifying and being careful. Very appreciate!

@PowerKiKi PowerKiKi merged commit 3dcc5ca into PHPOffice:master Apr 26, 2020
@PowerKiKi
Copy link
Member

Thank you for the well crafted PR and your patience.

@TimGa TimGa deleted the fix-issue-1364 branch May 2, 2020 08:01
@drola drola mentioned this pull request Jun 1, 2020
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Removing last row incorrect behavior
3 participants