简体   繁体   English

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

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

I am using apache POI to read excel.i have a requirement that the the value in the excel should only be integer.我正在使用 apache POI 读取 excel。我要求 excel 中的值只能是整数。 I have done this我已经做到了

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

but it is applicable for all numeric values.但它适用于所有数值。 But i want to check only for integer.Plese help.I dont find any thing in this XSSFCell to check integer.但我只想检查整数。请帮助。我在这个 XSSFCell 中找不到任何东西来检查整数。

you should try and add another condition您应该尝试添加另一个条件

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

}

You can get the cell value and check if it's value changes when you round it.您可以获取单元格值并检查其值是否在四舍五入时发生变化。 It doesn't use the POI library, but get's the job done:它不使用 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