如何在jasper报告中的最后一页和中间页上启用不同的页眉? [英] How to enable different page headers on last and middle pages in jasper reports?

查看:73
本文介绍了如何在jasper报告中的最后一页和中间页上启用不同的页眉?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要启用具有3种页面标题的报告:第一页面标题",中间页面标题"和最后页面标题".所有这些标头可以具有不同数量的报告元素,并且可以位于不同的位置.页脚也一样.

I need to enable the reports with 3 types of the page headers: "first page header", "middle pages header" and "last page header". All of these headers can have different number of report elements and on different positions. Same goes for the footers.

注意::报告必须在其Detail区域中支持报告元素,例如 jr:table jr:list .这些元素必须通过xml数据源与数据一起提供.

NOTE: The report must support the report elements like jr:table or jr:list in its Detail band. These element must be supplied with the data via xml datasources.

我可以使用Title乐队来模拟首页标题,但是在启用中间页标题"和最后一页标题"时遇到了问题.这就是我想要做的:

I was able to simulate first page header by using Title band, but I'm having problems enabling "middle pages header" and "last page header". This is what I'm trying to do:

<pageHeader>
<band height="100" splitType="Stretch">
    <frame>
        <reportElement x="0" y="0" height="100" width="555" uuid="f788c74b-6853-4bc7-8ed7-5e3d538287c9" isRemoveLineWhenBlank="true">
            <printWhenExpression>
                <![CDATA[new Boolean($V{PAGE_NUMBER} == $V{PAGE_COUNT})]]>
            </printWhenExpression>
        </reportElement>
        <staticText>
            <reportElement x="1" y="1" width="100" height="20" uuid="9777208b-5323-4045-aa49-a849d5c00c89"/>
            <text><![CDATA[LAST PAGE HEADER TEXT 1]]></text>
        </staticText>
        <staticText>
            <reportElement x="50" y="10" width="200" height="50" uuid="15313676-09e6-4d17-ac75-2df99f61bfee"/>
            <text><![CDATA[LAST PAGE HEADER TEXT 2]]></text>
        </staticText>
    </frame>
    <frame>
        <reportElement x="0" y="0" height="100" width="555" uuid="65577abd-8717-477a-f27e-c70e9eba46af" isRemoveLineWhenBlank="true">
            <printWhenExpression>
                <![CDATA[new Boolean($V{PAGE_NUMBER} != 1) && new Boolean($V{PAGE_NUMBER} != $V{PAGE_COUNT})]]>
            </printWhenExpression>
        </reportElement>
        <staticText>
            <reportElement x="70" y="0" width="300" height="100" uuid="0a866eb3-85cf-4376-d6a4-21b534d36df0"/>
            <text><![CDATA[MIDDLE PAGE HEADER TEXT 1]]></text>
        </staticText>
    </frame>
</band>
</pageHeader>

我正在将frame块与printWhenExpression一起使用.根据printWhenExpression条件,仅应打印两个frame块之一(及其所有内容).第一个框架块应呈现最后一页页眉",第二个框架应呈现中间页标题".

I'm using frame blocks along with printWhenExpression. Depending on the printWhenExpression condition, only one of two frame blocks should be printed (with all of its content). First frame block should render "last page header", and second one should render "middle pages header".

问题出在第一个frame(最后一页标题")printWhenExpression中:

The problem lies within the first frame ("last page header") printWhenExpression:

<printWhenExpression>
    <![CDATA[new Boolean($V{PAGE_NUMBER} == $V{PAGE_COUNT})]]>
</printWhenExpression>

在这种情况下,由于评估时间的原因,$V{PAGE_NUMBER}始终等于$V{PAGE_COUNT}.

In this case, $V{PAGE_NUMBER} always equals $V{PAGE_COUNT} because of the evaluation time.

有什么方法可以检查当前页面是否为最后一页?另外,还有其他方法可以启用中间页"和最后一页"标头吗?

Is there any way to check if the current page is the last page? Also, is there any other way to enable "middle pages" and "last page" headers?

注意:通过使用framesLast Page Footer带,我能够为页脚实现类似的逻辑!

NOTE: I was able to implement similar logic for the footers by using the frames and Last Page Footer band!

推荐答案

首先:$V{PAGE_COUNT}

生成当前页面时已处理的记录数.因此,您在该页面中拥有的记录数,而不是页面数计数...

the number of records that were processed when generating the current page. Hence the number of records you have in the page, not a page number count...

pageFooterlastPageFooter中,reportElement可以具有负Y 坐标(如果IDE不允许这样做,则需要手动编辑jrxml). y =-700",可让您将信息放入pageHeader和最后一个pageHeader ...

In pageFooter and lastPageFooter the reportElement can have negative Y coordinates (if IDE does not allow this then you need to edit manually the jrxml) es. y="-700", which allows you to put information in pageHeader and last pageHeader...

第一页

在框架内使用:

<printWhenExpression><![CDATA[new Boolean($V{PAGE_NUMBER}.intValue()==1)]]></printWhenExpression>

  • pageHeader 使用title带或将帧放在pageFooter中并使用负y坐标.
  • pageFooter ,使用pageFooter乐队
    • pageHeader use title band or put frame in pageFooter and use negative y coordinate.
    • pageFooter, use pageFooter band

    • 中间页

      在框架上使用:

      <printWhenExpression><![CDATA[new Boolean($V{PAGE_NUMBER}.intValue()>1)]]></printWhenExpression>
      

      • pageHeader 将框架放在pageFooter中,并使用负y坐标.
      • pageFooter ,使用pageFooter乐队.
        • pageHeader put frame in pageFooter and use negative y coordinate.
        • pageFooter, use pageFooter band.

        • 最后一页

          • pageHeader ,将框架放在lastPageFooter中,并使用负y坐标.
          • pageFooter ,使用lastPageFooter乐队
          • pageHeader, put frame in lastPageFooter and use negative y coordinate.
          • pageFooter, use lastPageFooter band


          注意::要为此虚拟页面生成空间,请在标头中包含一个空的pageHeader,其宽度要设置为


          NOTE: To generate space for this virtual pageHeader include an empty pageHeader with desired band height

          玩得开心!

          这篇关于如何在jasper报告中的最后一页和中间页上启用不同的页眉?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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