当我的jasper报告只有一页时,如何隐藏y的页面x [英] How to hide the page x of y when my jasper report has only one page
本文介绍了当我的jasper报告只有一页时,如何隐藏y的页面x的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用jasper-reports 4.5.0并且我正在生成报告。我的要求是如果我的报告只有一个页面那么它不应该显示页面1 0f 1.我怎么能这样做。要显示页面x of y我使用下面的代码行。
I am using jasper-reports 4.5.0 and i am generating the reports.My requirement is if my report has only one page then it should not display the page 1 0f 1.How can i do this.To display the page x of y I am using the below lines of code.
<textField>
<reportElement x="395" y="121" width="20" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[$V{PAGE_NUMBER}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="350" y="121" width="45" height="20"/>
<textElement/>
<textFieldExpression><![CDATA["PAGE"]]></textFieldExpression>
</textField>
<textField>
<reportElement x="415" y="121" width="25" height="20"/>
<textElement/>
<textFieldExpression><![CDATA["OF"]]></textFieldExpression>
</textField>
<textField evaluationTime="Report">
<reportElement x="440" y="121" width="19" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[$V{PAGE_NUMBER}]]></textFieldExpression>
</textField>
这是新修改的代码。
<variable name="NPAGES" class="java.lang.Integer" calculation="Highest">
<variableExpression><![CDATA[$V{PAGE_NUMBER}]]></variableExpression>
<initialValueExpression><![CDATA[$V{PAGE_NUMBER}]]></initialValueExpression>
</variable>
<textField>
<reportElement x="395" y="121" width="20" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[($V{NPAGES} > 1) ? $V{PAGE_NUMBER} : ""]]></textFieldExpression>
</textField>
<textField>
<reportElement x="350" y="121" width="45" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[($V{NPAGES} > 1) ? "PAGE" : ""]]></textFieldExpression>
</textField>
<textField>
<reportElement x="415" y="121" width="25" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[($V{NPAGES} > 1) ? "OF" : ""]]></textFieldExpression>
</textField>
<textField>
<reportElement x="440" y="121" width="19" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[($V{NPAGES} > 1) ? $V{NPAGES} : ""]]></textFieldExpression>
</textField>
推荐答案
定义一个变量NPAGES,设置为总数报告中的页面:
Define a variable NPAGES which is set to the total number of pages in the report:
<variable name="NPAGES" class="java.lang.Integer" calculation="Highest">
<variableExpression><![CDATA[$V{PAGE_NUMBER}]]></variableExpression>
<initialValueExpression><![CDATA[$V{PAGE_NUMBER}]]></initialValueExpression>
</variable>
现在,使用该变量作为条件来确定是否显示页码:
Now, use that variable as a conditional to determine whether to display the Page Number:
<textField>
<reportElement x="395" y="121" width="20" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[($V{NPAGES} > 1) ? $V{PAGE_NUMBER} : ""]]></textFieldExpression>
</textField>
<textField>
<reportElement x="350" y="121" width="45" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[($V{NPAGES} > 1) ? "PAGE" : ""]]></textFieldExpression>
</textField>
<textField>
<reportElement x="415" y="121" width="25" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[($V{NPAGES} > 1) ? "OF" : ""]]></textFieldExpression>
</textField>
<textField>
<reportElement x="440" y="121" width="19" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[($V{NPAGES} > 1) ? $V{NPAGES} : ""]]></textFieldExpression>
</textField>
我在我的一份报告中试过这个并且它有效。
I tried this in one of my reports and it worked.
这篇关于当我的jasper报告只有一页时,如何隐藏y的页面x的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文