How to display the page x of y for only the reports which are having more than one page

旧时模样 提交于 2020-01-04 02:12:14

问题


I am using the jasper reports-4.5.0. I am generating the reports in different formats using this jasper. I want to display the page X of Y in my reports. So I am using iReport provided page number text field which is available in palette. It is displaying the page number in all the reports even the reports which are having the single page also.

So my requirement is I don't want the page x of y if my report has only one page. How do I accomplish this?

The below code is presently i am using according to the given answer.

<textField>
                    <reportElement x="395" y="121" width="20" height="20">
                       <printWhenExpression><![CDATA[$V{PAGE_COUNT} > 1]]></printWhenExpression>
                    </reportElement>
                    <textElement textAlignment="Right"/>
                    <textFieldExpression><![CDATA["Page "+$V{PAGE_NUMBER}+" of"]]></textFieldExpression>
                </textField>
                <textField evaluationTime="Report">
                    <reportElement x="350" y="121" width="45" height="20">
                    <printWhenExpression><![CDATA[$V{PAGE_COUNT} > 1]]></printWhenExpression>
                    </reportElement>
                    <textElement/>
                    <textFieldExpression><![CDATA[" " + $V{PAGE_NUMBER}]]></textFieldExpression>
                </textField>

If i used like this i am not getting the page numbers in the reports which are having the more than one page.


回答1:


You need to set the Print When Expression for the two fields that contain "Page "+$V{PAGE_NUMBER}+" of" and " " + $V{PAGE_NUMBER}. The jrxml portion with this two fields should look something like:

<textField>
    <reportElement uuid="90a3462d-cfa2-4768-904a-1edf4191f1b7" x="250" y="16" width="80" height="20">
        <printWhenExpression><![CDATA[$V{PAGE_COUNT} > 1]]></printWhenExpression>
    </reportElement>
    <textElement textAlignment="Right"/>
    <textFieldExpression><![CDATA["Page "+$V{PAGE_NUMBER}+" of"]]></textFieldExpression>
</textField>
<textField evaluationTime="Report">
    <reportElement uuid="01d43267-3247-48bb-9822-8b58ea860d7f" x="330" y="16" width="40" height="20">
        <printWhenExpression><![CDATA[$V{PAGE_COUNT} > 1]]></printWhenExpression>
    </reportElement>
    <textElement/>
    <textFieldExpression><![CDATA[" " + $V{PAGE_NUMBER}]]></textFieldExpression>
</textField>


来源:https://stackoverflow.com/questions/11242490/how-to-display-the-page-x-of-y-for-only-the-reports-which-are-having-more-than-o

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!