JXL 解决#VALUE 问题

发布于 2024-10-15 06:43:06 字数 1313 浏览 3 评论 0原文

我想使用 AVERAGE 函数,但是当我有一个恰好是标签的参考单元格时,我得到 #VALUE 作为输出。

我已经附上了我想要做的示例代码:

String filename = "C:\\input.xls";     
WorkbookSettings ws = new WorkbookSettings();      
ws.setLocale(new Locale("en", "EN"));      
WritableWorkbook workbook = Workbook.createWorkbook(new File(filename), ws);     
WritableSheet s1 = workbook.createSheet("Output", 0);     
s1.addCell(new Number(1,2,6));      
s1.addCell(new Number(3, 1, 6));       
s1.addCell(new Number(3, 2, 1));      
s1.addCell(new Number(3, 3, 6));      
s1.addCell(new Label(3, 4, ""));      
Formula formula = new 
 Formula(3,5,"AVERAGE(Output!D1,Output!D2,Output!D3,Output!D4,Output!D5)");      
s1.addCell(formula);  
workbook.write();
workbook.close();

我无法将空单元格转换为 0,因为 AVG 值会改变。

已使用 JAR

jxl-2.6.jar

实时而不是标签,将根据公式使用值

IF(Some-cell-reference="","",some-Value)

但是;当我尝试使用键 F2 编辑单元格时,它会更改其执行计划,并且我会得到正确的输出。

有没有可用的解决方案...

预期解决方案:

将单元格设置为空,但更改单元格格式,以便不返回#VALUE。

略有相关

这篇文章与JXL #VALUE 参考其他工作表时出现问题

I want to use AVERAGE function, but when I have a reference cell which happens to be a label I get #VALUE as the output.

I have attached the sample piece of code for what I am trying to do:

String filename = "C:\\input.xls";     
WorkbookSettings ws = new WorkbookSettings();      
ws.setLocale(new Locale("en", "EN"));      
WritableWorkbook workbook = Workbook.createWorkbook(new File(filename), ws);     
WritableSheet s1 = workbook.createSheet("Output", 0);     
s1.addCell(new Number(1,2,6));      
s1.addCell(new Number(3, 1, 6));       
s1.addCell(new Number(3, 2, 1));      
s1.addCell(new Number(3, 3, 6));      
s1.addCell(new Label(3, 4, ""));      
Formula formula = new 
 Formula(3,5,"AVERAGE(Output!D1,Output!D2,Output!D3,Output!D4,Output!D5)");      
s1.addCell(formula);  
workbook.write();
workbook.close();

I cannot convert the empty cell to 0 since the AVG value will change.

JAR USED

jxl-2.6.jar

In real time instead of Label the value will be used based on a formula

IF(Some-cell-reference="","",some-Value)

However; when I try to edit the cell with key F2 it changes its execution plan and I get the correct output .

Is there any solution available for this....

Expected solution :

To make the cell as empty but change the cell format so that #VALUE is not returned.

This post is slightly related to

JXL #VALUE problem with reference to other sheet

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

烈酒灼喉 2024-10-22 06:43:06

好的,我看到的第一个问题是您要添加的数字位于“C”列而不是“D”列中。也许“D”中已经有数字,所以这不是问题,但需要考虑。

我认为最大的问题是 jxl 处理电子表格的方式,这个 其他提问者认为他们的命名范围不是在插入公式之前创建的,因此他们只有在像您一样“进入”单元格时才起作用。因此,您的“输出”表可能未初始化,因此输出没有有效的参考!参考。

由于您还在同一张工作表中插入公式,因此转储工作表引用并像这样编写您的行:

Formula formula = new Formula(3,5,"AVERAGE(D1:D5)");

Ok, the first problem I see is that the numbers you're adding in are in column "C" not "D". Maybe you already have numbers in "D", so it's not a problem, but something to consider.

I think the big problem is the way that jxl works the spreadsheet, this other questioner thought that their named range wasn't created before their formula was inserted, so they had it only work when they went "into" the cell, as you did. So it may be that your "Output" sheet is not initializing so there's no valid reference for the Output! references.

Since you're also inserting the Formula in the same sheet, then dump the sheet references and write your line like this:

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