简体   繁体   English

openxml和Excel 15位数字的限制

[英]openxml and Excel 15 digits number limit

I am using POI from apache to read from an Excel file in a java program. 我正在使用来自Apache的POI从Java程序中的Excel文件读取。 The excel has macros that I have reproduced in Java but when I compare the results, there are small rounding differences that I am trying to eradicate as much as possible. excel具有我用Java复制的宏,但是当我比较结果时,有一些小的舍入差异,我试图尽可能地消除。 After downloading the code of POI 3.13 and running it in debug mode I realized that they are not handling numbers like Excel, which is using only 15 digits and adding non-significant 0s after, but instead using a representation on 17 digits. 下载POI 3.13的代码并在调试模式下运行后,我意识到它们没有像Excel那样处理数字,Excel仅使用15位数字,之后再添加非有效的0,而是使用17位数字的表示形式。 You can see that here . 您可以在这里看到。 But going deeper, it seems that POI is using openxml and that openxml Cell already store the floating point numbers on 17 digits instead of 15... So it seems to me that there is a bug in handling number in openxml but I am quite surprised that something that "big" as badly handling floating point numbers hasn't been spotted before as I can't find anything about that. 但是更深入一点,看来POI正在使用openxml,而openxml单元格已经将浮点数存储在17位而不是15位上。所以在我看来,在openxml中处理数字存在错误,但是我很惊讶以前没有发现“大”的东西来处理浮点数,因为我找不到任何东西。

So my question : is there a workaround to get the exact same 15 digits of Excel when using POI? 所以我的问题是:有一种解决方法可以在使用POI时获得完全相同的15位Excel? And better, can openxml be corrected to act like Excel on this matter? 更好的方法是,在此问题上,openxml是否可以更正为类似于Excel?

but I am quite surprised that something that "big" as badly handling floating point numbers hasn't been spotted before 但令我惊讶的是,以前没有发现“大”字样处理浮点数不好

Excel's use of floating-point is misguided, as well-documented in §2 of this article . Excel的浮点用法是错误的,如本文的§2 所述 Microsoft's poor attempt to pretend that values are 15-digit decimal floating-point when they are really 53-digit binary floating-point only makes things worse, and rather than emulating it, you should avoid using Excel for serious computations. Microsoft试图将值实际上是53位二进制浮点数时,假装值是15位十进制浮点数,这只会使情况变得更糟,而不是模仿它,您应该避免使用Excel进行认真的计算。 Here is a quote from the conclusion of §2: 以下是第2节结论的引文:

How can a user of Excel predict which functions act upon displayed instead of actual values? Excel用户如何预测所显示的功能而不是实际值? Which expressions get rounded cosmetically before being displayed? 哪些表情在显示之前会经过修饰四舍五入? The user's program cannot be debugged without an awareness of these questions, and an aware user ends up debugging Microsoft's pious fraud instead of just a malfunctioning Excel spreadsheet. 如果不了解这些问题就无法调试用户的程序,并且有意识的用户最终会调试Microsoft的虔诚欺诈行为,而不仅仅是调试出现故障的Excel电子表格。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM