显示“Y的页面X”使用单个文本字段 [英] Show "Page X of Y" using a single text field
问题描述
我想创建一个包含 Y
的第X页的文本字段,而不按照常用解决方案将其拆分为两部分。我的文本字段包含Page+ $ V {currentPage} +of+ $ V {PAGE_NUMBER}
, evaluationTime = auto
。
假设我有一个10页的报告。其中三个是标题带,六个是细节带,其中一个是摘要频段。标题频段,我的结果显示第0页,共10页
s,摘要带的细节带,然后第0页,共10页
的正确计数。
你如何确保在任何地方计算变量,不仅仅是细节带?
Jaspersoft Studio,6 +
对于Jaspersoft Studio v6,或者如果第一个页码重复,请尝试
将表达式设置为 1
可防止其值 null
。也就是说,如果页脚显示 Page null 为4 ,则可能表示尚未设置表达式。
创建变量。
添加页脚
添加 Page Footer 乐队如下:
- 在大纲面板中选择报告
- 检查页面页眉和页脚的摘要以确保页面页脚显示在摘要页面上。
- 添加页脚条带。
页脚已添加。
创建文本字段
创建一个文本字段,如下所示:
- 拖放单个文本字段到页面页脚区域。
- 选择文本字段。
- 设置表达式 to:
msg({1}的页面{0},$ V {V_CURRENT_PAGE_NUMBER},$ V {PAGE_NUMBER})
- 设置 Evalutat离子时间到:
自动
这些设置如图所示下图:
创建单个文本字段。
预览报告
对于包含三个页面和摘要页面的报告,预览报告显示:
摘要页面显示:
参见Robert Ensinger的 blog关于此主题的帖子了解更多详情。
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
.
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+
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 Variable
Create a variable as follows:
- 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}
- 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.
- If the page number shows
- Set Reset type to:
Page
These settings are illustrated in the following figure:
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.
The variable is created.
Add Page Footer
Add a Page Footer band as follows:
- 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.
The footer is added.
Create Text Field
Create a text field as follows:
- 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
These settings are illustrated in the following figure:
The single text field is created.
Preview Report
For a report with three pages plus a summary page, previewing the report shows:
The summary page shows:
See Robert Ensinger's blog post on this subject for more details.
这篇关于显示“Y的页面X”使用单个文本字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!