这是一种删除行的常用方法
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) {
// to verify that I am dealing with the last row
System.out.println(sheet.getRow(lastRowNum).getCell(0).toString() ;
// I created a unique string for the last row so that to make sure everything is ok
sheet.removeRow(removingRow); // does not always work
}
}
}
但由于某种原因,最后一行并不总是被删除。我用System.out.println
有人遇到过这个吗?我该如何处理?
答案 0 :(得分:1)
尝试这样做:
int lastRowNum = sheet.getLastRowNum()+ 1;