返回十进制而不是字符串(POI jar) [英] returning decimal instead of string (POI jar)

查看:29
本文介绍了返回十进制而不是字符串(POI jar)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要阅读 xls 或 xlsx 表.我成功地阅读了工作表,但它返回十进制值而不是字符串(例如:对于 3 - 它返回 3.0).我需要按原样读取单元格值.所以我需要以字符串形式返回

I need to read xls or xlsx sheet. successfully I read the sheet, but it returning decimal value instead of string (eg: for 3 -- it is returning 3.0). I need to read the cell values as it is. so I need to return as string

推荐答案

POI 为您提供 Excel 存储在文件中的确切值.通常,如果您在 Excel 单元格中写入数字,Excel 会将其存储为带有格式的数字.如果您愿意,POI 支持为您进行格式化(大多数人不这样做 - 他们希望数字作为数字以便他们可以使用它们)

POI is giving you the exact value that Excel has stored in the File. Generally, if you write a number in an Excel cell, Excel will store that as a number with formatting. POI provides support to do that formatting for you if you want it (most people don't - they want the numbers as numbers so they can use them)

您要查找的类是 DataFormatter.您的代码将类似于

The class you're looking for is DataFormatter. Your code would be something like

 DataFormatter fmt = new DataFormatter();
 for (Row r : sheet) {
    for (Cell c : r) {
       CellReference cr = new CellRefence(c);
       System.out.println("Cell " + cr.formatAsString() + " is " + 
                          fmt.formatCellValue(c) );
    }
 }

这篇关于返回十进制而不是字符串(POI jar)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆