9

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

4

1 に答える 1

1

最初の問題は、追加する数値が「D」列ではなく「C」列にあることです。おそらく、「D」にはすでに数字があるので、問題ではありませんが、考慮すべきことがあります。

大きな問題は jxl がスプレッドシートを操作する方法だと思います。この他の質問者は、数式が挿入される前に名前付き範囲が作成されなかったと考えていたため、セルに「入った」ときにのみ機能しました。 . したがって、「出力」シートが初期化されていない可能性があるため、出力の有効な参照がありません! 参照。

数式も同じシートに挿入しているので、シート参照をダンプして、次のように行を記述します。

Formula formula = new Formula(3,5,"AVERAGE(D1:D5)");
于 2011-06-27T21:48:31.253 に答える