如何从iReport中的子报表获取report_count [英] How to get report_count from subreport in iReport
问题描述
我的主报告中有一个子报告。
I have a sub report in my main report .
如果子报告没有返回任何行,我需要隐藏文本。
I need to hide a text if sub report returns no rows.
我试图获取子报告的记录数量,在主报告中添加一个新变量,并将其设置为的目标变量
<$ c的属性$ c> subreport(对于rount_count),但是当我运行主报表时,变量的值为null
I tried to get the number of records of subreport adding a new variable in main report and setting it as destination variable in return values
property of subreport(for rount_count)
, but when I run the main report, the value of variable is null
推荐答案
计算子报告中的记录
-
在主报告中定义变量
<variable name="subReportCount" class="java.lang.Integer"/>
调用子报告时,将返回参数设置为变量
<subreport>
<reportElement x="100" y="20" width="400" height="20" uuid="a7a89ebb-54d4-4b6e-8c9f-c107e8a40bbb"/>
<dataSourceExpression><![CDATA[... your datasource ...]]></dataSourceExpression>
<returnValue subreportVariable="REPORT_COUNT" toVariable="subReportCount"/>
<subreportExpression><![CDATA[$P{SUBREPORT_DIR} + "Your_subreport.jasper"]]></subreportExpression>
</subreport>
此变量现在可用于 textField
,但是你需要小心,因为 textField
需要在正确的时间进行评估(在子报告执行之后) )。
This variable can now be used in a textField
, however you need to be careful since the textField
need's to be evaluate at the correct time (after subreport has been executed).
textField
上的属性是评估时间
示例
<textField evaluationTime="Report" pattern="###0">
<reportElement positionType="Float" x="300" y="60" width="200" height="20" uuid="125aa2d0-3d4e-4377-bed1-b4531c9142c9"/>
<textElement textAlignment="Right" verticalAlignment="Middle"/>
<textFieldExpression><![CDATA[$V{subReportCount}]]></textFieldExpression>
</textField>
评估时间:
自动评估时间表示参与
表达式的每个变量应在引擎决定的时间进行评估。
波段元素将在波段结束时进行评估。
列一个常量,指定在填充每列后应计算表达式。
组一个常量,指定在每次分组后应评估表达式。
Master 用于表示在主报告结束时进行评估。
现在一个常量,指定在遇到填充过程时,应在填充过程的确切时刻评估表达式。 />
页面一个常量,指定在填充每个页面后应评估表达式。
报告一个常量,指定应在填充过程结束时评估表达式。
Auto Evaluation time indicating that each variable participating in the expression should be evaluated at a time decided by the engine.
Band The element will be evaluated at band end.
Column A constant specifying that an expression should be evaluated after each column is filled.
Group A constant specifying that an expression should be evaluated after each group break.
Master Used for elements that are evaluated at the moment the master report ends.
Now A constant specifying that an expression should be evaluated at the exact moment in the filling process when it is encountered.
Page A constant specifying that an expression should be evaluated after each page is filled.
Report A constant specifying that an expression should be evaluated at the end of the filling process.
一般情况下使用子报告
- 如果它在详细信息带中并在数据源上重复设置
evalutationTime =Band
- 如果它只出现一组
evalutationTime =Report
- if it is in detail band and is repeated on datasource set
evalutationTime="Band"
- if it's present only one set
evalutationTime="Report"
这篇关于如何从iReport中的子报表获取report_count的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!