Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JXL solve #VALUE problem

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

like image 744
Balaji.N.S Avatar asked Jan 31 '11 16:01

Balaji.N.S


People also ask

What does JXL stand for?

Java Excel API (a.k.a. JXL API) allows users to read, write, create, and modify sheets in an Excel (. xls) workbook at runtime.

What is the difference between JXL and Apache POI?

Difference between JXL and POI is that Java JXL does not support the Excel 2007+ ". xlsx" format; it only supports ". xls" format. Apache POI supports both with a common design.

What is JXL library?

JExcel is a library (API) to read, write, display, and modify Excel files with . xls or . xlsx formats. API can be embedded with Java Swing and AWT. JExcel.

What are the basic features of JXL framework select all that apply?

It can read, write and modify data in Excel 95, 97, 2000, and 2003 spreadsheets. It Supports cell formatting like font, number and date formatting. It Supports styling of cells like shading, bordering, and coloring of cells.


1 Answers

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)");
like image 157
Lance Roberts Avatar answered Sep 24 '22 06:09

Lance Roberts