excel中的空白单元格没有给出Cell = Null

时间:2015-04-21 20:50:32

标签: java excel

我希望使用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。有人可以帮忙吗?

0 个答案:

没有答案