JXL 解决#VALUE 问题
我想使用 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。
略有相关
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好的,我看到的第一个问题是您要添加的数字位于“C”列而不是“D”列中。也许“D”中已经有数字,所以这不是问题,但需要考虑。
我认为最大的问题是 jxl 处理电子表格的方式,这个 其他提问者认为他们的命名范围不是在插入公式之前创建的,因此他们只有在像您一样“进入”单元格时才起作用。因此,您的“输出”表可能未初始化,因此输出没有有效的参考!参考。
由于您还在同一张工作表中插入公式,因此转储工作表引用并像这样编写您的行:
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: