Jasper Reports:一个记录中的y页x [英] Jasper Reports: page x of y within one record
问题描述
我有多条记录的报告,其中一条记录由1-5页组成。如何显示y的页面x
,其中 x
是实际记录的页数和 y
是实际记录的总页数?我有类似下面的 x
变量(在新记录上重置,按页面递增),但它不起作用(在每页x上有1个值):
I have report with multiple records, where one record is consisting of 1-5 pages. How to display "page x of y"
, where x
is a number of page for actual record and y
is total pages for actual record ? I have something like below for x
variable (reset on new record, incremet by page), but it doesn't work (on each page x have 1 value):
<variable name="x" class="java.lang.Integer" resetType="Group" resetGroup="report_count" incrementType="Page" calculation="Count">
<variableExpression><![CDATA[1]]></variableExpression>
<initialValueExpression><![CDATA[new Integer(1)]]></initialValueExpression>
</variable>
<!-- group by record -->
<group name="report_count" isStartNewPage="true">
<groupExpression><![CDATA[$V{REPORT_COUNT}]]></groupExpression>
</group>
<textField evaluationTime="Now" evaluationGroup="report_count">
<reportElement x="141" y="5" width="156" height="20"/>
<textElement textAlignment="Right"/>
<textFieldExpression><![CDATA["Page "+$V{x}+" of"]]></textFieldExpression>
</textField>
推荐答案
问题是计算=count
没有达到预期的效果。它返回 variableExpression
返回的非空值的计数。由于您的 variableExpression
仅返回单个值,因此该变量始终设置为1.
The problem is that calculation="count"
does not do what you are expecting it to. It returns the count of non-null values that your variableExpression
returns. As your variableExpression
only returns a single value, the variable is always set to 1.
一个简单的解决方案是将计算类型设置为Nothing
,并将variableExpression设置为 $ V {x} +1
An easy solution is to set the calculation type to "Nothing"
, and the variableExpression to $V{x}+1
ie:
<variable name="x" class="java.lang.Integer" resetType="Group" resetGroup="report_count" incrementType="Page" calculation="Nothing">
<variableExpression><![CDATA[$V{x} + 1]]></variableExpression>
<initialValueExpression><![CDATA[new Integer(1)]]></initialValueExpression>
</variable>
组
标记可以具有属性 isResetPageNumber
。设置为true时,它将在每个组的开头重置内置变量 PAGE_NUMBER
。由于您已经按照每条记录进行分组,我认为这应该可以为您提供所需的效果。
The group
tag can have the attribute isResetPageNumber
. When set to true it will reset the built-in variable PAGE_NUMBER
at the start of every group. As you are already grouping by each record, I think this should give you the effect you are looking for.
这篇关于Jasper Reports:一个记录中的y页x的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!