JXL命名区域公式显示不正确的值 [英] JXL Named Area Formulas Display the Incorrect Value

查看:177
本文介绍了JXL命名区域公式显示不正确的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用JXL编写Excel报告.我需要为报表使用命名区域,并基于这些区域使用公式.但是,加载Excel文件时,显示的值不正确.如果我单击该单元格,然后按Enter,则该值将更改且正确.我不知道如何使该值在加载时正确显示.有人知道强制Excel重新评估或为公式提供默认值的方法吗?

I am using JXL to write an Excel report. I need to use named areas for the report, and have formulas based off of them. However, when the Excel file loads, the values displayed are incorrect. If I click on the cell, and hit enter, the value changes and is correct. I can't figure out how to make the value appear correctly on load. Does anyone know a way to force Excel to re-evaluate, or to provide a default value for the Formula?

下面是我的代码的简化版本:

Below is a simplified version of my code:

excelWorkbook.addNameArea("NamedArea", excelSheet, column1, row1, column2, row2);
Formula formula = new Formula(columnNumber, rowNumber, "COUNT(NamedArea)");
excelSheet.addCell(formula);

推荐答案

我也遇到了一些公式字段的值不正确的问题,并且没有找到在线解决方案.经过一些自我调查,我发现例如如果您在一个单元格上具有以下公式

I have also been having an issue with some formula fields not having the correct values, and have found no solution online. With some self investigation I found that if for instance you have the following formula on a cell

Formula frmla = new Formula(col2, row0, "SUM(A1+A2)");
excelSheet.addCell(frmla);

由于使用了标签,以下内容不会在公式单元格中产生结果:

The following will not produce a result in the formula cell because of the use of Label:

Label lbl1 = new Label(col0, row0, "5", wrtbleCellFrmt);
Label lbl2 = new Label(col1, row0, "5", wrtbleCellFrmt);

由于使用了jxl.write.number,以下内容将产生正确的结果:

The following will produce correct results because of the use of jxl.write.number:

jxl.write.Number number1 = new jxl.write.Number(col0, row0, 5, wrtbleCellFrmt);
jxl.write.Number number2 = new jxl.write.Number(col0, row0, 5, wrtbleCellFrmt);

标签采用参数String,而数字采用Double,这可能是导致正确结果的原因.

Label takes a parameter String while Number takes in a Double, which probably is the cause for correct results.

这篇关于JXL命名区域公式显示不正确的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆