使用 JXL 公式(如 SUM() AVG() STDEV() 返回 #VALUE 时出现问题!当它引用另一张表中的值时

发布于 2024-10-08 21:24:29 字数 1352 浏览 1 评论 0原文

我想在工作表中填充一些值,然后使用 jxl Formula 从该工作表获取值并将其写入另一个工作表...

当我尝试运行此示例代码时,

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

 

我得到 AVG 列表中的最后一个值输出

=平均值(输出!D5)

使用的 JAR:jxl 1.0.jar....

尝试过的解决方案:

1)我没有给它一个公式,而是给它一个标签

标签标签=新标签 (3,5,"AVERAGE(输出!D1:输出!D5)");

我在单元格中获取了整个文本,并在单元格之前给出了“=”。它的作用就像一个魅力。但我希望使用 JXL API 来完成此操作

2) 将 JAR 更改为 jxl 2.6.jar

现在,当我尝试运行相同的内容时,我得到了 #VALUE!。细胞内容是

=AVERAGE(Output!D1:Output!D5) 但我仍然得到#VALUE!。

使用的 JAR:jxl 2.6.jar

仅当我转到该单元格并按 Tab 键或 F2 键时,此错误才会得到解决。

请提供一些解决方案

问候

N.S.Balaji

I want to populate some values in a sheet and then use jxl Formula to get the values from that sheet and write it to another sheet...

When I try to run this sample code

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

 

I am getting the last value in the AVG list has the output

=AVERAGE(Output!D5)

JAR Used : jxl 1.0.jar....

Solution tried :

1) Instead of giving it has a formula I gave it has label

Label label = new Label
(3,5,"AVERAGE(Output!D1:Output!D5)");

I got the entire text in the cell and gave '=' before the cell.. It worked like a charm. But I want this to be done with JXL API

2) Changed the JAR to jxl 2.6.jar

Now I am getting #VALUE! when I try to run the same. The cell content is

=AVERAGE(Output!D1:Output!D5) but still I get #VALUE!.

JAR Used : jxl 2.6.jar

This error is getting solved only when I go to that cell and press tab key or F2 key.

Please provide some solution

Regards

N.S.Balaji

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

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

发布评论

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

评论(2

昵称有卵用 2024-10-15 21:24:29

看起来 Excel 正在以一种奇怪的方式评估公式,这就是为什么您会看到 #VALUE!。要查看公式失败的原因,请单击公式单元格,然后转到“工具”>公式审核>评估公式。您将看到步骤如下:

AVERAGE(Output!D1:Output!D5)
=AVERAGE(5:Output!D5)
=AVERAGE(5:1)
=AVERAGE(#VALUE!)
=#VALUE!

但是当您在单元格上执行 F2+Enter 时,您将看到 Excel 更改其执行计划并获得正确的答案。

恐怕我能想到的解决此问题的唯一方法是使用逗号分隔的列表,而不是范围:

Formula formula = new Formula(3,5, "AVERAGE(Output!D1,Output!D2,Output!D3,Output!D4,Output!D5)");

It looks like excel is evaluating the formula in a strange way, hence why you are seeing #VALUE!. To see why the formula is failing, click on the formula cell and then go to Tools > Formula Auditing > Evaluate Formula. You will see that the steps are:

AVERAGE(Output!D1:Output!D5)
=AVERAGE(5:Output!D5)
=AVERAGE(5:1)
=AVERAGE(#VALUE!)
=#VALUE!

But when you execute F2+Enter on the cell, you will see that Excel changes its execution plan and gets the right answer.

I'm afraid the only thing I can think of to fix this is to use a comma-separated list, instead of a range:

Formula formula = new Formula(3,5, "AVERAGE(Output!D1,Output!D2,Output!D3,Output!D4,Output!D5)");
左耳近心 2024-10-15 21:24:29

如果输入例如 Z1 = "=Output!D1", Z2 = "=Output!D2"...,则可以解决此问题。
然后你在你最喜欢的单元格中尝试 AVERAGE(z1:z5)

You can fix this problem if you put in e.g. Z1 = "=Output!D1", Z2 = "=Output!D2"...
and later you try AVERAGE(z1:z5) in your favorite cell

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