问题描述
我需要启用具有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?
注意:通过使用frames
和Last 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}
是
在pageFooter
和lastPageFooter
中,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 inpageFooter
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报告中的最后一页和中间页上启用不同的页眉?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!