JXL 命名面积公式显示不正确的值
我正在使用 JXL 编写 Excel 报告。我需要为报告使用命名区域,并具有基于它们的公式。但是,加载 Excel 文件时,显示的值不正确。如果我单击单元格并按 Enter 键,则值会发生变化并且是正确的。我不知道如何使该值在加载时正确显示。有谁知道如何强制 Excel 重新计算,或为公式提供默认值?
下面是我的代码的简化版本:
excelWorkbook.addNameArea("NamedArea", excelSheet, column1, row1, column2, row2);
Formula formula = new Formula(columnNumber, rowNumber, "COUNT(NamedArea)");
excelSheet.addCell(formula);
I am using JXL to write an Excel report. I need to use named areas for the report, and have formulas based off of them. However, when the Excel file loads, the values displayed are incorrect. If I click on the cell, and hit enter, the value changes and is correct. I can't figure out how to make the value appear correctly on load. Does anyone know a way to force Excel to re-evaluate, or to provide a default value for the Formula?
Below is a simplified version of my code:
excelWorkbook.addNameArea("NamedArea", excelSheet, column1, row1, column2, row2);
Formula formula = new Formula(columnNumber, rowNumber, "COUNT(NamedArea)");
excelSheet.addCell(formula);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我还遇到了一些公式字段没有正确值的问题,并且在网上没有找到解决方案。经过一些自我调查,我发现,如果您在单元格上有以下公式,
由于使用了标签,以下内容不会在公式单元格中产生结果:
由于使用了 jxl.write,以下内容将产生正确的结果.number:
Label 接受一个参数 String,而 Number 接受一个 Double,这可能是正确结果的原因。
I have also been having an issue with some formula fields not having the correct values, and have found no solution online. With some self investigation I found that if for instance you have the following formula on a cell
The following will not produce a result in the formula cell because of the use of Label:
The following will produce correct results because of the use of jxl.write.number:
Label takes a parameter String while Number takes in a Double, which probably is the cause for correct results.
也许这有帮助。查找“setAutomaticFormulaCalculation”方法:
http ://jexcelapi.sourceforge.net/resources/javadocs/2_6_10/docs/index.html
Maybe this helps. Look for the "setAutomaticFormulaCalculation" method:
http://jexcelapi.sourceforge.net/resources/javadocs/2_6_10/docs/index.html
可悲的是,似乎没有真正解决这个问题。我认为这是 JXL 的问题。我认为由于某种原因,直到计算公式之后才设置命名区域。
Sadly, it's looking like there is not really a fix for this. I think it's a problem in JXL. I think for some reason the named areas are not being set until after the formulas are evaluated.
今天我也遇到了错误#VALUE。这是这个公式:
当我按 F2 并在该单元格上输入时,它计算得很好,但在显示错误之前:“此公式中使用的值的数据类型错误”
我使用 Number 类来在该区域中输入数字,但我发现如果该范围内只有一个空白空间(如果您没有为该范围内的所有空间赋予值),则稍后会在电子表格中显示该错误。
解决方案:
我将公式移动到同一个列表1,进入单元格AF9:
首先计算它),然后仅将AF9的计算值复制到其他列表
之后工作正常,不再显示#VALUE。
Error #VALUE came up to me today too. It was this formula:
When I pressed F2 and enter on that cell it calculated it well but before it showed error: "A value used in this formula is of the wrong data type"
I used Number class to input numbers into that area but I found out that if there is only one empty space in that range (if you don't give value to all in the range) it will show that error in spreadsheet later.
Solution:
I moved formula to that same list1, into cell AF9:
to calculate it first) and then copied only calculated value of AF9 to other list
It worked ok after that and no more #VALUE showed up.