public class XSSFSheet { ... private void rebuildRows() { final boolean bRebuildCTSheetData=true; //rebuild the _rows map List rowList = new ArrayList<>(_rows.values()); _rows.clear(); for(XSSFRow r : rowList) { // Performance optimization: explicit boxing is slightly faster than auto-unboxing, though may use more memory final Integer rownumI = new Integer(r.getRowNum()); // NOSONAR _rows.put(rownumI, r); } if(bRebuildCTSheetData) { // Rebuild the CTSheetData.getRowList() final MapctRowMap=new TreeMap<>(); for(CTRow ctRow:getCTWorksheet().getSheetData().getRowList()) { final Long rowNum=new Long(ctRow.getR()); ctRowMap.put(rowNum,ctRow); } final CTRow rowArray[]=new CTRow[ctRowMap.size()]; ctRowMap.values().toArray(rowArray); getCTWorksheet().getSheetData().setRowArray(rowArray); } } }