Apache POI 电子表格是否有任何库可以处理比双精度更高精度的公式的读写?
最初,我想要一个比简单的 +-*/ 更多功能的 BigDecimal,它比 java.lang.Math 上可用的功能要少得多。
请不要对 sin 和产生或需要不适合的无理数的类似函数发表评论。该问题的简单答案是使用具有适当/合理精度限制的 MathContext。我最初只选择 BigDecimal,只是因为它提供的精度位数多于双倍。
我的一个想法是利用 Apache Poi 库,希望它包含一个工作 Function 接口,并为电子表格中找到的所有(也许不是全部,但很多)函数提供真正的实现。不幸的是,浏览 javadoc 我找不到任何类似命名的接口/类。
- 是否有任何其他库可以帮助使用比 double 精度更高的东西在 poi excel 单元格上进行数学运算?
- 我能说的最好的办法就是利用 apache commons math ?
- 看来 org.apache.poi.hssf.record.formula.functions.* 中与数字相关的函数只能使用双精度数。
Initially i was after a BigDecimal with more functionality than the simple +-*/ which is significantly less than whats available on java.lang.Math.
Please no comments about sin and similar functions that produce or require irrational numbers not being a big fit. The simple answer to that question is to use MathContext with an appropriate/sensible precision limit. I had originally only selected BigDecimal simply because it offers more digits of precision that double.
One idea i had was to make use of the Apache Poi library hoping that it contained a working Function interface with real implementations for all (well maybe not all but lots of ) the functions that are found within a spreadsheet. Unfortunately browsing the javadoc i couldnt find anything similarly named interface/classes.
- Are there any other libraries that can help with doing maths on poi excel cells using something w/ more precision than double ?
- the best i can tell is to make use of apache commons math ?
- it appears that the number related functions in org.apache.poi.hssf.record.formula.functions.* only work w/ doubles.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Excel 格式在内部将所有数字存储为双精度数。因此,虽然您有可能计算出更高精度的答案,但如果您将它们存储回 Excel 文件中,您就会丢失它。此外,如果您让 Excel 本身计算值,那么它保存的答案将仅限于双精度。
如果您想使用 POI 进行公式计算,它主要围绕计算单元格的内容进行设置。一种选择是创建一个单元格,将公式设置到其中然后进行评估。 有关详细信息,请参阅 Apache POI 评估文档。
org.apache.poi.ss.formula.functions 包包含 POI 支持的所有 Excel 公式函数实现,但它们对您来说可能有点低(它们适用于 Ptgs、Ops 等)
The excel format stores all numbers internally as a double. So, while you could potentially calculate answers to a higher precision, if you stored them back into an excel file you'd loose that. Additionally, if you got excel to calculate the value itself, then the answer it'd save would be limited to double precision.
If you wanted to do formula evaluation with POI, it's mostly setup around evaluating the contents of a cell. One option is to create a cell, set your formula into it then evaluate. See the Apache POI eval documentation for details.
The
org.apache.poi.ss.formula.functions
package contains all the excel formula function implementations that POI supports, but they may be a bit low level for you (they work on Ptgs, Ops etc)是的,Andy Khan 的 JExcel 可以处理 公式。
Yes, Andy Khan's JExcel can handle formulas.