Jasper Reports显示“第X页,共Y页"使用单个文本字段 [英] Jasper Reports Show "Page X of Y" using a single text field
问题描述
根据通用解决方案,我想创建一个包含Page X of Y
的文本字段,而不将其分为两部分.我的文本字段包含"Page " + $V{currentPage} + " of " + $V{PAGE_NUMBER}"
和evaluationTime=auto
.
I would like to create one text field that contains Page X of Y
, without splitting it in two parts, as per the common solution. My textfield contains "Page " + $V{currentPage} + " of " + $V{PAGE_NUMBER}"
with evaluationTime=auto
.
假设我有一个10页的报告.三个是标题带,六个是详细带,一个是摘要带.我的结果显示标题带的"Page 0 of 10"
,详细带的正确计数,然后摘要带的"Page 0 of 10"
Let's say I have a report with 10 pages. Three are the Title Band, six are Detail Band and one is the Summary Band. My results show "Page 0 of 10"
for the Title Bands, correct counts for the Detail Bands, then "Page 0 of 10"
for the Summary Bands.
您如何确保不仅在明细波段上,还在各处计算变量?
How do you ensure the variable is calculated everywhere, not only on Detail Band?
推荐答案
Jaspersoft Studio,6岁以上
对于Jaspersoft Studio v6,或者如果首页编号重复,请尝试此解决方案,该解决方案使用$V{MASTER_CURRENT_PAGE}
和$V{MASTER_TOTAL_PAGE}
的评估时间为Master
.
Jaspersoft Studio, 6+
For Jaspersoft Studio v6, or if the first page number is duplicated, try this solution, which uses $V{MASTER_CURRENT_PAGE}
and $V{MASTER_TOTAL_PAGE}
with an evaluation time of Master
.
对于其他版本的Jaspersoft Studio,请尝试后续小节中概述的步骤.
For other versions of Jaspersoft Studio, try the steps outlined in the subsequent subsections.
创建一个变量,如下所示:
Create a variable as follows:
- 创建一个名为
V_CURRENT_PAGE_NUMBER
的变量
- 选择变量以打开其属性(如下图所示)
- 将表达式设置为:
1
- 将初始值表达式设置为:
$V{PAGE_NUMBER}
- Create a variable called
V_CURRENT_PAGE_NUMBER
- Select the variable to open its properties (illustrated below)
- Set Expression to:
1
- Set Initial Value Expression to:
$V{PAGE_NUMBER}
- 如果页码显示
0
,请使用$V{PAGE_NUMBER} + 1
. - 如果页码始终显示
1 of Y
,则将 Expression 设置为$V{PAGE_NUMBER}
而不是初始值表达式,并将初始值表达式留空. - If the page number shows
0
, use$V{PAGE_NUMBER} + 1
. - If the page number always shows
1 of Y
, set Expression to$V{PAGE_NUMBER}
instead of the initial value expression, and leave the initial value expression empty. - 将重置类型设置为:
Page
- Set Reset type to:
Page
- 在大纲面板中选择报告
- 选中带有页眉和页脚的摘要" ,以确保页脚显示在摘要页上.
- 添加页面页脚带.
- Select the report in the outline panel
- Check Summary With Page Header And Footer to ensure the page footer appears on the summary page.
- Add a Page Footer band.
- 将单个文本字段拖放到 Page Footer 区域.
- 选择文本字段.
- 将表达式设置为:
msg("Page {0} of {1}", $V{V_CURRENT_PAGE_NUMBER}, $V{PAGE_NUMBER})
- 将评估时间设置为:
Auto
- Drag and drop a single text field onto the Page Footer band.
- Select the text field.
- Set Expression to:
msg("Page {0} of {1}", $V{V_CURRENT_PAGE_NUMBER}, $V{PAGE_NUMBER})
- Set Evalutation Time to:
Auto
这些设置如下图所示:
将表达式设置为1
可以防止其值成为null
.也就是说,如果页脚显示第 null 页为4 ,则可能表示尚未设置 Expression .
Setting the Expression to 1
prevents its value from being null
. That is, if the footer shows Page null of 4 it probably means that the Expression hasn't been set.
变量已创建.
添加一个页面页脚带,如下所示:
Add a Page Footer band as follows:
已添加页脚.
创建一个文本字段,如下所示:
Create a text field as follows:
这些设置如下图所示:
单个文本字段已创建.
对于具有三页加摘要页面的报告,预览报告显示:
For a report with three pages plus a summary page, previewing the report shows:
摘要页面显示:
这篇关于Jasper Reports显示“第X页,共Y页"使用单个文本字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!