How to determine empty row?

后端 未结 9 1900
情书的邮戳
情书的邮戳 2020-12-23 10:18

How I can determine empty rows in .xls documents using Apache POI?

9条回答
  •  清歌不尽
    2020-12-23 10:48

    Assuming you want to check if row n is empty, remembering that rows in Apache POI are zero based not one based, you'd want something like:

     Row r = sheet.getRow(n-1); // 2nd row = row 1
     boolean hasData = true;
    
     if (r == null) {
        // Row has never been used
        hasData = false;
     } else {
        // Check to see if all cells in the row are blank (empty)
        hasData = false;
        for (Cell c : r) {
           if (c.getCellType() != Cell.CELL_TYPE_BLANK) {
             hasData = true;
             break;
           }
        }
     }
    

提交回复
热议问题