【问题标题】:How to get current page number and total pages as variables on each page? [duplicate]如何获取当前页码和总页数作为每页上的变量? [复制]
【发布时间】:2012-06-22 16:15:48
【问题描述】:

我需要在报告上生成 OMR 代​​码。我考虑在每个页面上调用一些服务方法,以获取页码和总页数作为参数。问题是:如何将这些值(页码、总页数)作为每页上的变量?

<background>
    <band height="797">
        <textField>
            <reportElement x="30" y="684" width="100" height="97"/>
            <textFieldExpression><![CDATA[OMRService.generateCode($V{totalPages},$V{pageNumber})]]></textFieldExpression>
        </textField>
    </band>
</background>

【问题讨论】:

    标签: jasper-reports


    【解决方案1】:

    下面有示例代码如何在 2 个不同的文本字段中执行此操作。

    <textField evaluationTime="Page">
            <reportElement x="0" y="0" width="520" height="15"/>
            <textElement textAlignment="Right"/>
            <textFieldExpression class="java.lang.Integer"><![CDATA[$V{PAGE_NUMBER}+"/"]]>  </textFieldExpression>
    </textField>
    <textField evaluationTime="Report">
            <reportElement x="521" y="0" width="14" height="15"/>
            <textElement textAlignment="Left"/>
            <textFieldExpression class="java.lang.Integer"><![CDATA[$V{PAGE_NUMBER}]]></textFieldExpression>
    </textField>
    

    evaluationTime="Page" 时会显示页码,"Report" 时会显示总页数。我不知道如何将它合并到一个文本字段中(甚至不知道它是否可能 - 我花了很多时间在它上面但无法解决这个问题)。

    【讨论】:

      【解决方案2】:

      选择文本字段。
      将表达式设置为:msg("Page {0} of {1}", $V{V_CURRENT_PAGE_NUMBER}, $V{PAGE_NUMBER})
      将评估时间设置为:自动

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2013-01-14
        • 2016-08-14
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-08-05
        相关资源
        最近更新 更多