java 如何在 Ireport 或 jasper 报告中找到列的总和?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6593626/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 16:31:58  来源:igfitidea点击:

How to find sum of column in Ireport or jasper report?

javaprintingjasper-reportsireport

提问by kinkajou

I have column in detail band with value

我有带价值的详细列

$F{thScore}+$F{prScore}

$F{thScore}+$F{prScore}

I would like to find the sum of this column in run time . How is this possible in jasper report using Ireport. I did it with variable but with no luck.

我想在运行时找到此列的总和。这在使用 Ireport 的 jasper 报告中怎么可能。我用变量做到了,但没有运气。

采纳答案by kinkajou

A variable is defined and

定义了一个变量并且

variable expression

变量表达式

to

$F{thScore}+$F{prScore}

$F{thScore}+$F{prScore}

and

calculation

计算

to

sum

.It worked for me where $F{thScore},$F{prScore} are fields in detail band.

.它对我有用,其中 $F{thScore},$F{prScore} 是细节带中的字段。

回答by Abhi

I had a fields of Integer type and was trying to add the columns . I was not getting any error when the report is previewed but my java application was failing to compile the report and giving the error as

我有一个 Integer 类型的字段,并试图添加列。预览报告时我没有收到任何错误,但我的 Java 应用程序无法编译报告并将错误显示为

The operator + is undefined for the argument type(s) java.lang.Integer, java.lang.Integer value = (java.lang.Integer)(((java.lang.Integer)field_nBSRptSchm1Col1.getValue())+((java.lang.Integer)field_nBSRptSchm2Col1.getValue())); //$JR_EXPR_ID=8$

运算符 + 未定义参数类型 java.lang.Integer, java.lang.Integer value = (java.lang.Integer)((((java.lang.Integer)field_nBSRptSchm1Col1.getValue())+(( java.lang.Integer)field_nBSRptSchm2Col1.getValue())); //$JR_EXPR_ID=8$

then I used the following code to add the columns of Integer type...

然后我使用以下代码添加整数类型的列...

new Integer($F{nSchm1Col1}.intValue() + $F{Schm2Col1}.intValue() )

where nSchm1Col1and Schm2col1are two fields which I want to add. This one worked for me

其中nSchm1Col1Schm2col1是我要添加的两个字段。这个对我有用