JXL 命名面积公式显示不正确的值

发布于 2024-11-16 16:03:52 字数 393 浏览 3 评论 0原文

我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

虚拟世界 2024-11-23 16:03:52

我还遇到了一些公式字段没有正确值的问题,并且在网上没有找到解决方案。经过一些自我调查,我发现,如果您在单元格上有以下公式,

Formula frmla = new Formula(col2, row0, "SUM(A1+A2)");
excelSheet.addCell(frmla);

由于使用了标签,以下内容不会在公式单元格中产生结果:

Label lbl1 = new Label(col0, row0, "5", wrtbleCellFrmt);
Label lbl2 = new Label(col1, row0, "5", wrtbleCellFrmt);

由于使用了 jxl.write,以下内容将产生正确的结果.nu​​mber:

jxl.write.Number number1 = new jxl.write.Number(col0, row0, 5, wrtbleCellFrmt);
jxl.write.Number number2 = new jxl.write.Number(col0, row0, 5, wrtbleCellFrmt);

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

Formula frmla = new Formula(col2, row0, "SUM(A1+A2)");
excelSheet.addCell(frmla);

The following will not produce a result in the formula cell because of the use of Label:

Label lbl1 = new Label(col0, row0, "5", wrtbleCellFrmt);
Label lbl2 = new Label(col1, row0, "5", wrtbleCellFrmt);

The following will produce correct results because of the use of jxl.write.number:

jxl.write.Number number1 = new jxl.write.Number(col0, row0, 5, wrtbleCellFrmt);
jxl.write.Number number2 = new jxl.write.Number(col0, row0, 5, wrtbleCellFrmt);

Label takes a parameter String while Number takes in a Double, which probably is the cause for correct results.

童话里做英雄 2024-11-23 16:03:52

也许这有帮助。查找“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

云醉月微眠 2024-11-23 16:03:52

可悲的是,似乎没有真正解决这个问题。我认为这是 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.

美胚控场 2024-11-23 16:03:52

今天我也遇到了错误#VALUE。这是这个公式:

=COUNTIF('list1'!A9:'list1'!AE9,>0)

当我按 F2 并在该单元格上输入时,它计算得很好,但在显示错误之前:“此公式中使用的值的数据类型错误”

我使用 Number 类来在该区域中输入数字,但我发现如果该范围内只有一个空白空间(如果您没有为该范围内的所有空间赋予值),则稍后会在电子表格中显示该错误。

解决方案:

我将公式移动到同一个列表1,进入单元格AF9:

=COUNTIF(A9:AE9,>0) 

首先计算它),然后仅将AF9的计算值复制到其他列表

='list1'!AF9

之后工作正常,不再显示#VALUE。

Error #VALUE came up to me today too. It was this formula:

=COUNTIF('list1'!A9:'list1'!AE9,>0)

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:

=COUNTIF(A9:AE9,>0) 

to calculate it first) and then copied only calculated value of AF9 to other list

='list1'!AF9

It worked ok after that and no more #VALUE showed up.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文