Problem when using JXL Formula like SUM() AVG() STDEV() returns #VALUE! when it refers values from another sheet
Asked Answered
C

2

4

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

Cleodell answered 20/12, 2010 at 13:48 Comment(0)
L
3

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)");
Lancer answered 20/12, 2010 at 15:13 Comment(2)
Ya I tried the same solution has you have listed here ....Reg Specifying Range has comma separated values I am afraid to accept this as a good solution since in real time (production environment) the Range would be very high hence comma-separated list is not a good option...... Thanks for your suggestion. Would be better if you could suggest some other work aroundCleodell
Agree to @Cleodell this is a tedious workaround for a long range of values. Thanks anyway!Kabob
H
0

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

Hernandes answered 14/7, 2016 at 11:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.