网上删除行代码:
/** * Remove a row by its index * @param sheet a Excel sheet * @param rowIndex a 0 based index of removing row */ public static void removeRow(Sheet sheet, int rowIndex) { int lastRowNum=sheet.getLastRowNum(); if(rowIndex>=0&&rowIndex<lastRowNum){ sheet.shiftRows(rowIndex+1,lastRowNum, -1); } if(rowIndex==lastRowNum){ Row removingRow=sheet.getRow(rowIndex); if(removingRow!=null){ sheet.removeRow(removingRow); } } }
在要删除的行下面其他行存在批注内容是,打开excel会报错,如图:
删除第2行,打开excel时报错:
修复后:
修复后>=2行里的批注全部删除,此bug在poi-3.11存在,在poi-3.12-bea1存在,目前尚未修复。
官网关于此bug的记录:https://bz.apache.org/bugzilla/show_bug.cgi?id=56017
只能等poi-3.12下一版本了。
全文完。