折旧的CellType方法

时间:2017-12-12 10:58:24

标签: java excel apache

我在这里看过其他论坛,提出解决方案的建议,但我没有让他们工作。

我想检查单元格是 null还是空白,我使用的解压缩代码是(折旧了getCellType()和CELL_TYPE_BLANK):

if( (c == null) || c.getCellType() == c.CELL_TYPE_BLANK){
//do something
}

例如,我一直在寻找此主题中的解决方案:

  

Alternative to deprecated getCellType

我认为解决方案可能看起来像这样:

if( (c == null) || c.getCellTypeEnum() == CellType.BLANK){
//Error: incomparable types: org.apache.poi.ss.usermodel.CellType and int
//do something
}

if( (c == null) || c.getBooleanCellValue()){
//do something
}

但它确实有效,apaches文档也没那么有用。有没有人有解决方案可以产生警告?我使用的是poi 3.17。

BR

1 个答案:

答案 0 :(得分:0)

我一直在同一个问题上挣扎,我发现了以下作品。

这与您的方法相反。 我检查该值是否不为空。

下面的代码用于处理字符串值:

private static String checkForNullString(Cell cellToCheck) {
    String strCheck;
    if (cellToCheck != null && cellToCheck.getCellTypeEnum() != CellType.BLANK) {
        cellToCheck.setCellType(CellType.STRING);
        strCheck = cellToCheck.getStringCellValue();
    }
    else
        strCheck = "";
    return strCheck;
}

要处理数值,只需更改以下内容:

cellToCheck.getStringCellValue();

cellToCheck.getNumericCellValue());