我希望使用Java从我的Excel电子表格中删除空白行,但是当我尝试获取
时cell = lastRow.getCell(c,Row.RETURN_BLANK_AS_NULL);
对于空白单元格,它不会将单元格作为null。这是我的代码:
boolean stop = false;
boolean nonBlankRowFound;
int c;
HSSFRow lastRow = null;
HSSFCell cell1 = null;
while (stop == false) {
nonBlankRowFound = false;
lastRow = sheet.getRow(sheet.getLastRowNum());
for (c = lastRow.getFirstCellNum(); c <= lastRow.getLastCellNum(); c++) {
cell1 = lastRow.getCell(c);
if (cell1 != null && lastRow.getCell(c).getCellType() != HSSFCell.CELL_TYPE_BLANK) {
nonBlankRowFound = true;
}
}
if (nonBlankRowFound == true) {
stop = true;
} else {
sheet.removeRow(lastRow);
}
}
在最后一行中,单元格在excelspreadsheet中为空,但是cell1不为null。有人可以帮忙吗?