返回小数,而不是字符串(POI JAR) [英] returning decimal instead of string (POI jar)

查看:166
本文介绍了返回小数,而不是字符串(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 。您code会是这样

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天全站免登陆