如何在JasperReports中使用另一个变量的值递增变量? [英] How can I increment a variable with value of another variable in JasperReports?

查看:58
本文介绍了如何在JasperReports中使用另一个变量的值递增变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要对子报表中的所有项目进行总计.为此,我认为我需要为每个迭代将该变量的值添加到另一个变量,或将其递增"该值.每个组都会调用subReport,而我得到的是该组的总数.我需要添加变量值,而不是数据库列/字段.

I need to make a grand total of the items I'm counting in a subReport. To do that, I think I need to add the value of that variable to another variable for each iteration, or "increment" it by that value. The subReport gets called for each group, and I get a total for that group. I need to add the variable values, rather than database columns/fields.

我从subReport接收一个整数returnValue,它本身就是子报表中的行数.我想得到总计,因为subReport对于我的主SQL查询中的不同结果(每次针对GROUP)被多次调用.我想将所有结果加起来,但是得到一个null值.我尝试将subReport的操作添加为新的returnValue,然后选择Sum作为操作,但这也产生了null.

I'm receiving an integer returnValue from the subReport, which is itself the count of rows in the sub-report. I want to get the grand total, since that subReport is called multiple times for the different results (each for a GROUP) from my main SQL query. I want to add up all the results, but I'm getting a null value. I tried adding an operation to the subReport as a new returnValue and choosing Sum as the operation, but that also yielded a null.


   <variable name="itemCount" class="java.lang.Integer" resetType="None"/>
   <variable name="grandCount" 
      class="java.lang.Integer" 
      incrementType="Group" 
      incrementGroup="ITEM_BUNDLE">
      <variableExpression><![CDATA[$V{itemCount}]]></variableExpression>
   </variable>

... <returnValue subreportVariable="countItems" toVariable="itemCount"/>

... <returnValue subreportVariable="countItems" toVariable="itemCount"/>

推荐答案

将属性calculation="Sum"添加到variable name="grandCount"

或将grandCount作为参数传递给子报表

or pass grandCount to subreport as parameter

<subreportParameter name="grandCount">
<subreportParameterExpression><![CDATA[$P{grandCount}]]></subreportParameterExpression>
</subreportParameter>

在子报表中

声明具有参数 grantCount

<variable name="countItems" .... >
   <variableExpression><![CDATA[$P{itemCount} + $P{grandCount}]]></variableExpression>
   <initialValueExpression><![CDATA[$P{grandCount}]]></initialValueExpression>
</variable>

然后返回

<returnValue subreportVariable="countItems" toVariable="grandCount" calculation="Sum"/>

这篇关于如何在JasperReports中使用另一个变量的值递增变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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