Jasper reports Jasper报告:子报告中的页码不起作用

Jasper reports Jasper报告:子报告中的页码不起作用,jasper-reports,subreport,Jasper Reports,Subreport,我的应用程序中有几个类似的报告,因此我创建了一个基本结构,在标题中有一个子报告,在页脚中有另一个子报告 问题是我有70份类似的报告,如果有一天我需要更改页脚结构,我不想更改70份报告,我只希望更改一份 在页脚子报表中,我有以下内容: <?xml version="1.0" encoding="UTF-8"?> <jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="h

我的应用程序中有几个类似的报告,因此我创建了一个基本结构,在标题中有一个子报告,在页脚中有另一个子报告

问题是我有70份类似的报告,如果有一天我需要更改页脚结构,我不想更改70份报告,我只希望更改一份

在页脚子报表中,我有以下内容:

<?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="reportFooterV" pageWidth="550" pageHeight="650" orientation="Landscape" whenNoDataType="AllSectionsNoDetail" columnWidth="550" leftMargin="0" rightMargin="0" topMargin="0" bottomMargin="0" uuid="6a63a92f-0859-4b0b-84b8-6166c2fe0951">
    <property name="ireport.zoom" value="1.5"/>
    <property name="ireport.x" value="19"/>
    <property name="ireport.y" value="0"/>
    <parameter name="date" class="java.lang.String" isForPrompting="false"/>
    <title>
        <band height="19">
            <textField>
                <reportElement uuid="89a04d3d-73e0-4f28-9747-3206c4022769" x="0" y="0" width="191" height="19" forecolor="#999999"/>
                <textElement verticalAlignment="Bottom">
                    <font fontName="Roboto" size="10" isBold="false"/>
                </textElement>
                <textFieldExpression><![CDATA[$P{date}]]></textFieldExpression>
            </textField>
            <textField evaluationTime="Auto">
                <reportElement uuid="89a04d3d-73e0-4f28-9747-3206c4022769" x="352" y="0" width="99" height="19" forecolor="#999999"/>
                <textElement textAlignment="Right" verticalAlignment="Bottom">
                    <font fontName="Roboto" size="10" isBold="false"/>
                </textElement>
                <textFieldExpression><![CDATA[$V{PAGE_NUMBER}]]></textFieldExpression>
            </textField>
        </band>
    </title>
</jasperReport>

但是可变页码不起作用,总是在页面中显示1

在主报告中,我在pageFooter区域有这个

<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="systemParametersSummary" pageWidth="595" pageHeight="842" whenNoDataType="AllSectionsNoDetail" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" resourceBundle="properties.Messages" isIgnorePagination="true" uuid="6a63a92f-0859-4b0b-84b8-6166c2fe0951">

....
    <pageFooter>
        <band height="22">
            <subreport>
                <reportElement uuid="ac3cfc74-4e5a-45bc-945a-7ca6c82c4f6a" x="2" y="0" width="150" height="22"/>
                <subreportParameter name="date">
                    <subreportParameterExpression><![CDATA[$P{date}]]></subreportParameterExpression>
                </subreportParameter>
                <subreportExpression><![CDATA[$P{footer}]]></subreportExpression>
            </subreport>
        </band>
    </pageFooter>
</jasperReport>

....

我不知道为什么我找不到解决这个问题的方法,如果有人能帮我…谢谢

如果您仅使用这些子报告进行页面编号,则这就是您出错的原因。每个子报告只有一页长,因此始终是第1页,共1页

通常也不需要以这种方式使用子报表进行页面编号,因为调用子报表的开销超过了您从中获得的任何好处

我建议您放弃子报表,只允许主报表使用主报表引擎数据完成繁重的工作,例如,在主报表页脚中输入日期的文本字段,并使用以下代码进行页面编号:

<textField evaluationTime="Master">
    <reportElement uuid="89a04d3d-73e0-4f28-9747-3206c4022769" x="352" y="0" width="99" height="19" forecolor="#999999"/>
        <textElement textAlignment="Right" verticalAlignment="Bottom">
            <font fontName="Roboto" size="10" isBold="false"/>
    </textElement>
    <textFieldExpression><![CDATA[$V{MASTER_CURRENT_PAGE} + " of " + $V{MASTER_TOTAL_PAGES}]]></textFieldExpression>
</textField>

因此,在您的主要报告中,您应该以以下内容结束:

<pageFooter>
        <band height="22">
            <textField>
            <reportElement uuid="89a04d3d-73e0-4f28-9747-3206c4022769" x="0" y="0" width="191" height="19" forecolor="#999999"/>
            <textElement verticalAlignment="Bottom">
                <font fontName="Roboto" size="10" isBold="false"/>
            </textElement>
            <textFieldExpression><![CDATA[$P{date}]]></textFieldExpression>
        </textField>
        <textField evaluationTime="Master">
            <reportElement uuid="89a04d3d-73e0-4f28-9747-3206c4022769" x="352" y="0" width="99" height="19" forecolor="#999999"/>
            <textElement textAlignment="Right" verticalAlignment="Bottom">
                <font fontName="Roboto" size="10" isBold="false"/>
            </textElement>
            <textFieldExpression><![CDATA[$V{MASTER_CURRENT_PAGE} + " of " + $V{MASTER_TOTAL_PAGES}]]></textFieldExpression>
        </textField>
    </band>
</pageFooter>

不要忘了,如果您在主报告标题栏中使用子报告用于类似的目的,那么您可能也应该重新考虑该方法

如果有具体原因,您可以在子报告中应用与原始问题相同的逻辑。当您使用母版页编号时,这也将给出正确的结果,例如,您的子报告代码如下所示:

<?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="reportFooterV" pageWidth="550" pageHeight="650" orientation="Landscape" whenNoDataType="AllSectionsNoDetail" columnWidth="550" leftMargin="0" rightMargin="0" topMargin="0" bottomMargin="0" uuid="6a63a92f-0859-4b0b-84b8-6166c2fe0951">
    <parameter name="date" class="java.lang.String" isForPrompting="false"/>
    <title>
        <band height="22">
            <textField>
                <reportElement x="0" y="0" width="191" height="19" forecolor="#999999" uuid="89a04d3d-73e0-4f28-9747-3206c4022769"/>
                <textElement verticalAlignment="Bottom">
                    <font fontName="Roboto" size="10" isBold="false"/>
                </textElement>
                <textFieldExpression><![CDATA[$P{date}]]></textFieldExpression>
            </textField>
            <textField evaluationTime="Master">
                <reportElement x="352" y="0" width="99" height="19" forecolor="#999999" uuid="89a04d3d-73e0-4f28-9747-3206c4022769"/>
                <textElement textAlignment="Right" verticalAlignment="Bottom">
                    <font fontName="Roboto" size="10" isBold="false"/>
                </textElement>
                <textFieldExpression><![CDATA[$V{MASTER_CURRENT_PAGE} + " of " + $V{MASTER_TOTAL_PAGES}]]></textFieldExpression>
            </textField>
        </band>
    </title>
</jasperReport>

这是一个老问题,但现在在我的页脚子报表中有一个可变的MASTER_TOTAL_PAGES


相应的母版当前页面对我不起作用,但您可以很容易地从主报告中输入当前页码。

可能重复&Hi Victor,与我的原始答案相同的逻辑适用,因此我对其进行了编辑,以向您展示另一种方法。希望这能有所帮助。