Jasper Reports显示“第X页,共Y页"使用单个文本字段 [英] Jasper Reports Show "Page X of Y" using a single text field

查看:84
本文介绍了Jasper Reports显示“第X页,共Y页"使用单个文本字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据通用解决方案,我想创建一个包含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:

  1. 创建一个名为V_CURRENT_PAGE_NUMBER
  2. 的变量
  3. 选择变量以打开其属性(如下图所示)
  4. 表达式设置为:1
  5. 初始值表达式设置为:$V{PAGE_NUMBER}
  1. Create a variable called V_CURRENT_PAGE_NUMBER
  2. Select the variable to open its properties (illustrated below)
  3. Set Expression to: 1
  4. 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.
      1. 重置类型设置为:Page
      1. Set Reset type to: Page

      这些设置如下图所示:

      表达式设置为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:

      1. 在大纲面板中选择报告
      2. 选中带有页眉和页脚的摘要" ,以确保页脚显示在摘要页上.
      3. 添加页面页脚带.
      1. Select the report in the outline panel
      2. Check Summary With Page Header And Footer to ensure the page footer appears on the summary page.
      3. Add a Page Footer band.

      已添加页脚.

      创建一个文本字段,如下所示:

      Create a text field as follows:

      1. 单个文本字段拖放到 Page Footer 区域.
      2. 选择文本字段.
      3. 表达式设置为:msg("Page {0} of {1}", $V{V_CURRENT_PAGE_NUMBER}, $V{PAGE_NUMBER})
      4. 评估时间设置为:Auto
      1. Drag and drop a single text field onto the Page Footer band.
      2. Select the text field.
      3. Set Expression to: msg("Page {0} of {1}", $V{V_CURRENT_PAGE_NUMBER}, $V{PAGE_NUMBER})
      4. Set Evalutation Time to: Auto

      这些设置如下图所示:

      单个文本字段已创建.

      对于具有三页加摘要页面的报告,预览报告显示:

      For a report with three pages plus a summary page, previewing the report shows:

      摘要页面显示:

      这篇关于Jasper Reports显示“第X页,共Y页"使用单个文本字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆