我的主报告中有一个子报告。
如果子报告没有返回行,我需要隐藏文本。
我试图获取子报表的记录数,在主报表中添加一个新变量并将其设置为 return values
subreport(for rount_count)
属性中的目标变量, 但是当我运行主报表时,变量的值为 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
需要在正确的时间进行评估(在执行子报表之后).
textField
的属性是 evaluationTime
例子
<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>
评估时间:
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"
关于jasper-reports - 如何从iReport中的子报表中获取report_count,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34679789/