is it possible print element only when its detail band is the last on page?

喜欢而已 提交于 2020-01-14 14:14:51

问题


Is it possible, to get a condition, that I can print an element only when its detail band is the last on page in Jasper Reports?

We can have variable saying record number on the page. But how we get the calculated total record on each page?


回答1:


This is done with the "reset type" on a variable

<?xml version="1.0" encoding="UTF-8"?>
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="report1" language="groovy" pageWidth="612" pageHeight="792" columnWidth="612" leftMargin="0" rightMargin="0" topMargin="10" bottomMargin="10" uuid="39852bd8-6125-4359-8d76-06927e7be492">
    <queryString>
        <![CDATA[SELECT ROWNUM N FROM dual  CONNECT BY LEVEL <= 200 ]]>
    </queryString>
    <field name="N" class="java.math.BigDecimal"/>
    <variable name="N_count_page" class="java.lang.Integer" resetType="Page" calculation="Count">
        <variableExpression><![CDATA[$F{N}]]></variableExpression>
    </variable>
    <variable name="N_count_report" class="java.lang.Integer" calculation="Count">
        <variableExpression><![CDATA[$F{N}]]></variableExpression>
    </variable>
    <title>
        <band height="20" splitType="Stretch">
            <textField>
                <reportElement uuid="93284d9f-1ee0-4a15-b227-31b55aa2e48b" x="0" y="0" width="376" height="20"/>
                <textElement textAlignment="Center">
                    <font size="14" isBold="true"/>
                </textElement>
                <textFieldExpression><![CDATA["Page Count"]]></textFieldExpression>
            </textField>
        </band>
    </title>
    <columnHeader>
        <band height="20">
            <staticText>
                <reportElement uuid="a7113fdd-591b-4fee-9123-981ab75c6fa6" mode="Opaque" x="0" y="0" width="100" height="20" forecolor="#FFFFFF" backcolor="#000000"/>
                <textElement/>
                <text><![CDATA[N]]></text>
            </staticText>
        </band>
    </columnHeader>
    <detail>
        <band height="20">
            <textField>
                <reportElement uuid="54bac746-4efb-4412-81bc-b4ba807c60fd" x="0" y="0" width="100" height="20"/>
                <textElement/>
                <textFieldExpression><![CDATA[$F{N}]]></textFieldExpression>
            </textField>
        </band>
    </detail>
    <pageFooter>
        <band height="50">
            <staticText>
                <reportElement uuid="4c685263-0ef7-4a68-a328-39901ef2806f" x="0" y="0" width="100" height="20"/>
                <textElement textAlignment="Right"/>
                <text><![CDATA[Rows on page :]]></text>
            </staticText>
            <textField>
                <reportElement uuid="c65214f1-82dc-476a-8439-087854bbc5c6" x="100" y="0" width="100" height="20"/>
                <textElement/>
                <textFieldExpression><![CDATA[$V{N_count_page}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement uuid="48b37aff-b169-4ca2-b9dd-30c026988f68" x="289" y="30" width="80" height="20"/>
                <textElement textAlignment="Right"/>
                <textFieldExpression><![CDATA["Page "+$V{PAGE_NUMBER}+" of"]]></textFieldExpression>
            </textField>
            <textField evaluationTime="Report">
                <reportElement uuid="983ccfed-d783-429e-bc6c-3fa488b2e106" x="369" y="30" width="40" height="20"/>
                <textElement/>
                <textFieldExpression><![CDATA[" " + $V{PAGE_NUMBER}]]></textFieldExpression>
            </textField>
        </band>
    </pageFooter>
    <lastPageFooter>
        <band height="64">
            <staticText>
                <reportElement uuid="240e2f86-991a-4fc1-941b-56cc43b28c25" x="0" y="24" width="100" height="20"/>
                <textElement textAlignment="Right"/>
                <text><![CDATA[Rows on report :]]></text>
            </staticText>
            <textField>
                <reportElement uuid="718d4481-4716-4071-9989-27d5119fb428" x="100" y="24" width="100" height="20"/>
                <textElement/>
                <textFieldExpression><![CDATA[$V{N_count_report}]]></textFieldExpression>
            </textField>
            <textField evaluationTime="Report">
                <reportElement uuid="f03359be-3bbe-4da8-9bd8-ac024aa6f289" x="369" y="44" width="40" height="20"/>
                <textElement/>
                <textFieldExpression><![CDATA[" " + $V{PAGE_NUMBER}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement uuid="ad4aa2c0-9ad8-4892-a16f-0bb584c93916" x="289" y="44" width="80" height="20"/>
                <textElement textAlignment="Right"/>
                <textFieldExpression><![CDATA["Page "+$V{PAGE_NUMBER}+" of"]]></textFieldExpression>
            </textField>
            <staticText>
                <reportElement uuid="b4bdd29a-4ef9-46cc-a57a-df7577bdd73f" x="0" y="0" width="100" height="20"/>
                <textElement textAlignment="Right"/>
                <text><![CDATA[Rows on page :]]></text>
            </staticText>
            <textField>
                <reportElement uuid="39952747-170c-4747-8e2c-0e12ab608ae9" x="100" y="0" width="100" height="20"/>
                <textElement/>
                <textFieldExpression><![CDATA[$V{N_count_page}]]></textFieldExpression>
            </textField>
        </band>
    </lastPageFooter>
</jasperReport>


来源:https://stackoverflow.com/questions/13047905/is-it-possible-print-element-only-when-its-detail-band-is-the-last-on-page

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