gpt4 book ai didi

apache-poi - Apache POI : How to format numeric cell values

转载 作者:行者123 更新时间:2023-12-02 03:51:53 24 4
gpt4 key购买 nike

我正在使用 Apache POI 3.9 进行 XLS/XLSX 文件处理。

在XLS表中,有一列数值为“3000053406”。

当我用 POI 阅读它时......

cell.getNumericCellValue()

它给了我像“3.00E+08”这样的值。这在我的应用程序中造成了巨大的问题。

如何在 Apcahe POI 中读取数据时设置数字格式?

我知道有一种方法是将列设置为“文本”类型。但是我想知道在读取数据时Apache POI端是否还有其他方法。或者我们可以使用简单的 java DecimalFormatter 格式化它吗?

最佳答案

这个经常出现....

采摘 one of my past answers to an almost identical question

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.

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 - Apache POI : How to format numeric cell values,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14079796/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com