【问题标题】:Number in excel is returned as a double number [duplicate]excel中的数字作为双数返回[重复]
【发布时间】:2016-02-23 12:29:49
【问题描述】:

我正在使用 POI 读取 Excel。在某些时候我读了一个单元格

while(rowIterator.hasNext()) { //read the rows
    Row row = rowIterator.next();
    String quantity = row.getCell(4).toString(); // it returns a string in 1000.0 
}

为什么我得到一个字符串 1000.0 而不是 1000 ? excel 中的值是通用格式,没有.,例如 1000、234、33、102 等。

【问题讨论】:

    标签: apache-poi


    【解决方案1】:

    在单元格上使用toString() 方法将返回单元格值的字符串表示形式。 如果您确定您的单元格会返回 Number,那么您应该在单元格上使用 getNumericCellValue()

    row.getCell(4).getNumericCellValue()
    

    【讨论】:

    • 太棒了!谢谢你的信息!
    猜你喜欢
    • 2014-12-14
    • 1970-01-01
    • 1970-01-01
    • 2021-09-13
    • 1970-01-01
    • 2020-09-02
    • 2014-03-28
    • 2014-09-08
    • 1970-01-01
    相关资源
    最近更新 更多