How to get an Excel Blank Cell Value in Apache POI?

后端 未结 9 1418
孤独总比滥情好
孤独总比滥情好 2020-12-01 05:02

I have a huge excel file with tons of columns which looks like this :-

Column1 Column2 Column3 Column4 Column5
abc             def             ghi
        mn         


        
相关标签:
9条回答
  • 2020-12-01 06:02
            for(org.apache.poi.ss.usermodel.Row tmp : hssfSheet){
                for(int i = 0; i<8;i++){
                    System.out.println(tmp.getCell(i));
                }               
            }
    
    0 讨论(0)
  • 2020-12-01 06:02
    for (Row row: sheet){
    // This will return null if cell is empty / blank
    Cell cell = row.getCell(columnNumber);
    }
    
    0 讨论(0)
  • 2020-12-01 06:03

    If you want to get all cells, no matter if they exist or not, then the iterator isn't for you. Instead, you need to manually fetch the appropriate cells, likely with a missing cell policy

    for(Row row : sheet) {
       for(int cn=0; cn<row.getLastCellNum(); cn++) {
           // If the cell is missing from the file, generate a blank one
           // (Works by specifying a MissingCellPolicy)
           Cell cell = row.getCell(cn, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK);
           // Print the cell for debugging
           System.out.println("CELL: " + cn + " --> " + cell.toString());
       }
    }
    

    There's more details on all of this in the Apache POI documentation on iterating over cells

    0 讨论(0)
提交回复
热议问题