Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Fix an edge case when ranges got unmerged when the adjacent range of the same size got deleted #2358

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

Merged
merged 1 commit into from
Jul 1, 2024

Conversation

Pankraty
Copy link
Member

@Pankraty Pankraty commented Jun 28, 2024

As @masterworgen discovered by using ClosedXML.Report, there is an edge case causing a range to be unmerged.

Reproduction:

            var wb = new XLWorkbook("Template.xlsx");

            var range = wb.Worksheets.First().Range("A5:F5");
            range.Delete(XLShiftDeletedCells.ShiftCellsUp);

            wb.SaveAs("result.xlsx");

Original file:

image

Expected result:

image

Actual result:

image

Template.xlsx

This happens if there is a merged range of exactly same size just below a range to be deleted (with ShiftCellsUps mode), or to the right of it (when ShiftCellsLeft mode is used).

The reason of such a behavior is the usage of ranges repository: when all affected ranges are being adjusted in NotifyRangeShiftedRows/NotifyRangeShiftedColumns, first we update the merged range and it becomes the exact clone of the range to be deleted (therefore, they both are "optimized" by the repository to reference the same instance); and then the deleted range gets destoyed, together with the merged one.

In the PR, I am handling this edge case: if any range becomes identical to the original one then we don't have to process this range outside the loop.

@Pankraty Pankraty changed the title WIP: Fix an egde case when ranges got unmerged when the adjacent range of the same size got deleted WIP: Fix an edge case when ranges got unmerged when the adjacent range of the same size got deleted Jun 28, 2024
@Pankraty Pankraty changed the title WIP: Fix an edge case when ranges got unmerged when the adjacent range of the same size got deleted Fix an edge case when ranges got unmerged when the adjacent range of the same size got deleted Jun 28, 2024
@Pankraty Pankraty marked this pull request as ready for review June 28, 2024 13:43
@Pankraty Pankraty added the bug label Jun 28, 2024
@Pankraty Pankraty requested a review from jahav June 28, 2024 14:03
Copy link
Member

@jahav jahav left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks for the fix.

@jahav jahav added this to the v0.104 milestone Jul 1, 2024
@jahav jahav merged commit 6c16c36 into develop Jul 1, 2024
6 checks passed
@jahav jahav deleted the fix-unmerge branch July 1, 2024 22:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants