Apache的POI:如何格式化数字的单元格值 [英] Apache POI : How to format numeric cell values

查看:562
本文介绍了Apache的POI:如何格式化数字的单元格值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Apache POI 3.9 XLS / XLSX文件处理。

I am using Apache POI 3.9 for XLS/XLSX file processing.

在XLS表,还有像数值列3000053406。

In the XLS sheet, there is a column with numeric value like "3000053406".

当我用POI与阅读它。

When I read it with POI with..

cell.getNumericCellValue()

这给了我价值,如3.00E + 08。这在我的应用创造巨大的问题。

It gives me value like "3.00E+08". This create huge problem in my application.

如何能我设置的数量,而在Apcahe POI?

How can I set the number formatting while reading data in Apcahe POI ?

有一种方法,我知道是设置栏为文本类型。但我想知道是否有任何其他方式在Apache的POI一边读取数据。或者可以通过我们使用简单的Java DecimalFormatter格式化?

There is a way that I know is to set the column as "text" type. But I want to know if there is any other way at Apache POI side while reading the data. OR can we format it by using simple java DecimalFormatter ?

推荐答案

这其中经常出现....

This one comes up very often....

过去的答案之一,几乎相同的问题

您想要做的是使用 DataFormatter类。你通过这一个单元格,并会尽力回报你什么包含Excel中会告诉你该小区的字符串。如果你传递一个字符串单元格,你会得到的字符串返回。如果你传递一个数字细胞与应用格式规则,它会格式化基于它们的数量,并给你的字符串返回。

What you want to do is use the DataFormatter class. You pass this a cell, and it does its best to return you a string containing what Excel would show you for that cell. If you pass it a string cell, you'll get the string back. If you pass it a numeric cell with formatting rules applied, it will format the number based on them and give you the string back.

有关你的情况,我会假设数字单元应用了一个整数格式规则。如果你问DataFormatter格式化这些细胞,它会给你回在它的整数字符串的字符串。

For your case, I'd assume that the numeric cells have an integer formatting rule applied to them. If you ask DataFormatter to format those cells, it'll give you back a string with the integer string in it.

这篇关于Apache的POI:如何格式化数字的单元格值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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