如何从iReport中的子报表中获取report_count

How to get report_count from subreport in iReport

我的主报告中有一个子报告。

如果子报告 returns 没有行,我需要隐藏文本。

我试图获取子报表的记录数,在主报表中添加一个新变量并将其设置为 subreport(for rount_count)return values 属性 中的目标变量,但是当我 运行主报表,变量值为null

统计子报表中的记录

  1. 在主报表中定义一个变量

    <variable name="subReportCount" class="java.lang.Integer"/>
    
  2. 调用子报表时将return参数设置为变量

    <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"