Bug 64046

Summary: shiftRows judge mergedRegions to remove error
Product: POI Reporter: YueshanLin <lin_yueshan>
Component: XSSFAssignee: POI Developers List <dev>
Status: NEW ---    
Severity: normal    
Priority: P2    
Version: 4.1.1-FINAL   
Target Milestone: ---   
Hardware: PC   
OS: Mac OS X 10.1   
Attachments: shift the second row occur error

Description YueshanLin 2020-01-03 09:37:19 UTC
Created attachment 36944 [details]
shift the second row occur error

The method of removalNeeded in abstract class RowShifter exist bug, the CellRangeAddress of overwrite is defined as "overwrite = new CellRangeAddress(firstRow, lastRow, 0, 0);". If the delete row's first column is not a mergedRegion, then all the mergedRegion in the Row will not be deleted, when to add mergeRegion, will occur IllegalStateException of "Cannot add merged region " + candidateRegion.formatAsString() + " to sheet because it overlaps with an existing merged region (" + existingRegion.formatAsString() + ").
My solution: the overwrite CellRangeAddress should be defined as "overwrite = new CellRangeAddress(firstRow, lastRow, 0, Integer.MAX_VALUE);", then all the mergedRegion in the deleteRow will be deleted, then can shiftRow successfully.