Bug 57307

Summary: removeMergedRegion() throws IndexOutOfBoundsException on .xlsx MS-Excel file
Product: POI Reporter: Prejith Pulikkottil <pulikkot>
Component: XSSFAssignee: POI Developers List <dev>
Status: RESOLVED WONTFIX    
Severity: normal    
Priority: P2    
Version: 3.10-FINAL   
Target Milestone: ---   
Hardware: PC   
OS: All   
Attachments: removeMergedRegion tested excel

Description Prejith Pulikkottil 2014-12-04 12:22:08 UTC
Created attachment 32259 [details]
removeMergedRegion tested excel

removeMergedRegion() throws an IndexOutOfBoundsException on .xlsx file. But is working on .xls file

Here I have pasted the tested the code 

void removeRow(Sheet sheet){
    if(sheet){
        for(i in sheet.getFirstRowNum()..sheet.getLastRowNum()){
            Row row = sheet.getRow(i)
            if(!row){
                continue
            }
            for(j in row.getFirstCellNum()..row.getLastCellNum()){
                if(j<0){
                    continue
                }
                sheet.removeMergedRegion(j)
            }
            sheet.removeMergedRegion(i)
            sheet.removeRow(row)
        }
    }
}
Comment 1 Andreas Beeker 2014-12-06 14:25:23 UTC
Merged regions aren't addressed via the row/cell index.

Although I think the handling in the hssf method InternalSheet.removeMergedRegion() is wrong and it actually should throw an IOOB, I won't fix this handling, as it potentially breaks (a lot of) user code.