Bug 69154 - Shifting columns with merged regions generates an error about overlapping regions
Summary: Shifting columns with merged regions generates an error about overlapping reg...
Status: NEW
Alias: None
Product: POI
Classification: Unclassified
Component: XSSF (show other bugs)
Version: 5.2.2-FINAL
Hardware: PC All
: P2 normal (vote)
Target Milestone: ---
Assignee: POI Developers List
Depends on:
Reported: 2024-06-26 06:57 UTC by Jesper Jørgensen
Modified: 2024-07-02 13:11 UTC (History)
0 users

Unit Test file that shows the error (2.12 KB, text/plain)
2024-06-26 06:57 UTC, Jesper Jørgensen

Note You need to log in before you can comment on or make changes to this bug.
Description Jesper Jørgensen 2024-06-26 06:57:42 UTC
Created attachment 39788 [details]
Unit Test file that shows the error

In some cases where an Excel document contains merged region shifting columns to the left generates an error of the form (region here are just examples):

Cannot add merged region E2:E3 to sheet because it overlaps with an existing merged region (D2:E2).

The attached Java class demonstrate the bug. It works fine with the merged regions at row 1 (index 0), but inserting a row above the region makes it fail.

The error is in ColumnShifter line 117:

overwrite = new CellRangeAddress(0, 0, firstCol, lastCol);

where it should be: 

overwrite = new CellRangeAddress(merged.getFirstRow(), merged.getLastRow(), firstCol, lastCol);

a similar error occurs in line 112. The problem is that it always refers to the first row (0) in the sheet and not to the the first row of the merged region.
Comment 1 PJ Fanning 2024-07-02 13:01:01 UTC
I've added r1918838

The changes only seem to work for XSSF. It appears that HSSF Column Shifter has a lot of disabled test scenarios and is quite incomplete.

Jesper - could you sanity check my change?

I haven't look at the row shifter. Would you be able to review the row shifting code too?
Comment 2 PJ Fanning 2024-07-02 13:11:25 UTC
I added r1918841 for rows. This does not seem to work properly. I will get back to debug this.