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

标签 jasper-reports

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

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

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

最佳答案

统计子报表中的记录

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

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

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

相关文章:

java - 在 jasper 报告生成期间,有时不会设置日期值

fonts - 为什么 Jasper Report 6.3 中的文本要换行?

java - 如何去除zxing生成的二维码的边距?

jasper-reports - 为 JasperReports 中 textField 数据中的特定单词添加样式

mysql - 如何在不设置sql模式的情况下在mysql中使用group by进行聚合?

java - DOCX 不支持表中超过 63 列?

java - 从 JasperReports 打印 PDF

image - JasperReports 中当其值为 NULL 或空时隐藏图像

excel - Jasper iReport 自定义日期和自定义时间

java - ireport 如何自动隐藏重复行? (部分重复信息)