如何阅读了Apache POI Excel文件的确切单元格内容 [英] how to read exact cell content of excel file in apache POI

查看:142
本文介绍了如何阅读了Apache POI Excel文件的确切单元格内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我读到细胞用于例如内容如果是在日期格式它施放到有些像2099年12月31日的另一个值 - > 46052和$ 50.00 - > 50和50.00% - > 0.5

但我要的是能为每一个细胞的确切字符串值。

我的code是这样的:

  cell.setCellType(Cell.CELL_TYPE_STRING);
字符串str = cell.getStringCellValue();


解决方案

无需显式格式, Apache的POI 提供的 DataFormatter 类实用工具利用内容的的格式,因为它出现的上出类拔萃。您可以选择自定义格式也一样,一个简单的例子是(细胞是参考你的 XSSFCell )对象:

 的System.out.println(新DataFormatter()formatCellValue(单元)。);

Excel表如下:

使用 DataFormatter (SOP以上语句)打印:

  50%
$ 1,200个
14年12月21日

如果你的正常的格式将打印:

  0.5
1200.0
12月21日 - 2014年

when I read a content of cell for e.g. if it is in date format it casts into some another value like 12/31/2099 -> 46052 and $50.00 -> 50 and 50.00% -> 0.5.

But what I want is to get the exact string value for every cell.

My Code is like this:

cell.setCellType(Cell.CELL_TYPE_STRING);
String str = cell.getStringCellValue();

解决方案

No need for explicit formatting, apache-poi provides for DataFormatter class as utility to leverage the format of the content as it appears on the excel. You can choose custom formats too, a simple example would be (cell is reference to your XSSFCell object):

System.out.println(new DataFormatter().formatCellValue(cell));

Excel sheet looks like:

Using DataFormatter (sop statement above) prints:

50%
$ 1,200
12/21/14

Where your normal formatting would print:

0.5
1200.0
21-Dec-2014

这篇关于如何阅读了Apache POI Excel文件的确切单元格内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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