POI 判断单行、单个单元格为空

1 判断单个单元格为空

//判断单个单元格是否为空
public static boolean isEmptyCell(Cell cell){
    if(cell==null||cell.getCellType().equals(CellType.BLANK)){
        return true;
    }
    return false;
}

2 判断单行是否为空

    /**
     * 判断该行是否为空
     * @param row 行对象
     * @return
     */
    public static boolean isEmptyRow(Row row){
        //行不存在
        if (row == null) {
            return true;
        }
        //第一个列位置
        int firstCellNum = row.getFirstCellNum();
        //最后一列位置
        int lastCellNum = row.getLastCellNum();
        //空列数量
        int nullCellNum = 0; 
        for (int c = firstCellNum; c < lastCellNum; c++) {
            Cell cell = row.getCell(c);
            if (null == cell || CellType.BLANK == cell.getCellType()) {
                nullCellNum ++;
                continue;
            }
            cell.setCellType(CellType.STRING);
            String cellValue = cell.getStringCellValue().trim();
            if (StringUtils.isEmpty(cellValue)) {
                nullCellNum ++;
            }
        }
        //所有列都为空
        if (nullCellNum == (lastCellNum - firstCellNum)) {
            return true;
        }
        return false;
    }

猜你喜欢

转载自blog.csdn.net/qq_38974638/article/details/114147735
今日推荐