繁体   English   中英

如何检查excel整数中的单元格或不在apache POI中

[英]How to check a cell in excel integer or not in apache POI

我正在使用 apache POI 读取 excel。我要求 excel 中的值只能是整数。 我已经做到了

if(cell.getCellType()==XSSFCell.CELL_TYPE_NUMERIC)

但它适用于所有数值。 但我只想检查整数。请帮助。我在这个 XSSFCell 中找不到任何东西来检查整数。

您应该尝试添加另一个条件

if(cell.getCellType()==XSSFCell.CELL_TYPE_NUMERIC)
{
    if(cell.getNumberCellValue instanceof Integer)
       do something

}

您可以获取单元格值并检查其值是否在四舍五入时发生变化。 它不使用 POI 库,但完成了工作:

Double numericCellValue = cell.getNumericCellValue();
if(Math.floor(numericCellValue) == numericCellValue){
    // It's an integer;
}
    Cell value=cols.next();
    if(value.getCellType()==CellType.NUMERIC)
    {
                        
       System.out.println((int)value.getNumericCellValue());
                    
    }
It will check is cellType is numeric which includes double also. But once confirmed, it will type cast it into numeric value.

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM