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) } } }
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.