如何在Jasper Reports Studio中使用初始值表达式来仅向第一行添加值? [英] How to use Initial Value Expression in Jasper Reports Studio to add value to only the first row?

查看:389
本文介绍了如何在Jasper Reports Studio中使用初始值表达式来仅向第一行添加值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对Jasper Reports Studio中初始值表达式的理解是,所述值应该是第一个值。所以我把它设置为:

My understanding of the initial value expression in Jasper Reports Studio is that it, the said value should be the first value. So I did set it to:

$F{rptran_units}.add(new BigDecimal(200))

和我的变量的表达式

$F{rptran_units}

并计算我的金额。

这是因为我希望我的变量表达式的第一个值加上200,后续值继续求和而不重复加200.我想我可能不会在正确的方式。我希望通过初始值表达式或任何其他可以帮助我实现目标的方法来澄清如何实现这一点。

This is because I want the first value of my variable expression to be have 200 added to it and subsequent values to continue summing without repeatedly adding 200. I guess I might not be going about it in the right way. I would appreciate some clarification on how I could achieve this using the initial value expression or any other method that would help me achieve my aim.

推荐答案

是的,您对初始值表达式的用法有轻微的误解,在您的示例中,在计算 $ F {rptran_units} 的总和时不会使用它,它只会在计算变量开始之前有这个值(细节带的第一次迭代)。

Yes you have slight misunderstanding what the initial value expression is used for, in your example it will not be used during the computation of the sum of $F{rptran_units}, it will only have that value before the computation of variable starts (first iteration of the detail band).

初始值是:


在第一次计算表达式之前从变量开始假设的值 - 参见 Jasper报告变量

但这并不意味着变量以此开头值如果你想计算一个字段的总和,实际上它不会传递给计算引擎,它就是wi ll仅在表达式中使用变量(本身)时使用,例如 $ V {variable1} +5 在上面的链接中

but this does not mean that the variable start with this value if you like to compute a sum on a field, actually it is not passed to the compute engine and it will only be used if you use the variable (itself) in the expression as example $V{variable1}+5 in the above link

然而,针对您的特定问题的解决方案(将 $ F {rptran_units} 的当前总和加200)非常简单,只需将200添加到变量在显示价值之前。

However the solution to your specific problem (add 200 to the current sum of $F{rptran_units}) is very simple, just add 200 to the variabile before displaying the value.

示例

<textField>
    <reportElement x="0" y="0" width="100" height="30" uuid="d7a0eb2f-0664-46ec-91f1-02d6de303c18"/>
    <textFieldExpression><![CDATA[$V{SumOfRptran_units}.add(new BigDecimal(200))]]></textFieldExpression>
</textField>

另一个解决方案是添加另一个变量,为此变量添加200并使用它。

Another solution is to add another variabile that adds 200 to this variable and use this.

<variable name="SumAdd200" class="java.math.BigDecimal">
    <variableExpression><![CDATA[$V{SumOfRptran_units}.add(new BigDecimal(200))]]></variableExpression>
</variable>

这篇关于如何在Jasper Reports Studio中使用初始值表达式来仅向第一行添加值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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