Jasper Reports:子报表内的页码不起作用 [英] Jasper Reports: Page Number inside subreport does not work

查看:182
本文介绍了Jasper Reports:子报表内的页码不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的应用程序中有几个类似的报告,因此我创建了一个基本结构,其中Title内有子报表,另一个在Page Footer中。

I have several similar reports in my application, for this reason i have created a basic structure with a subreport inside the Title and another one inside the Page Footer.

问题是我有70个类似的报告,如果有一天我需要更改页脚结构我不想更改70报告我更喜欢只更改一个。

The problem is that i have 70 similar reports and if one day i need to change the footer structure i dont wanna have to change 70 reports i prefer change only one.

在页脚子报告中我有:

<?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>

但变量PAGE_NUMBER不起作用,并且始终在页面中显示1。

But the variable PAGE_NUMBER, doesnt work and always show 1 in the page.

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

In the main report I have this in the pageFooter area

<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>

我不知道为什么我找不到这个的解决方法,如果有人可以帮助我...谢谢你好!

I dont know why i cant find the workaround for this, if anyone can help me...thank you!

推荐答案

如果您只是将这些子报告用于页码编号,那么这就是您获得错误。这些子报告中的每一个只有1页长,所以它总是第1页的第1页。

If you're only using these sub-reports for the page-numbering then this is why you are getting an error. Each of these sub-reports is only 1 page long, so it will always be page 1 of 1.

通常也不需要使用子报告页面以这种方式编号,因为调用子报告的开销超过了通常值得获得的任何好处。

Neither is there usually a need to use sub-reports for page numbering in this way, as the overhead for calling sub-reports is more than it's usually worth for any benefit you get from doing so.

我建议你得到摆脱你的子报告,只是允许主报告做重举,例如使用主报表引擎数据在整个报表中显示页码,方法是将日期的文本字段放在主报表页脚中,并使用此代码进行页码编号:

I'd suggest that you get rid of your sub-reports, and just allow the main report to do the heavy-lifting e.g. page numbers across a full report with the use of Master report engine data by putting your text field for the date in the main report footer and also using this code for the page numbering:

<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>

因此,在主报告中,您应该最终得到:

So, in your main report, you should end up with:

<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>

如果您在主报告标题带中使用子报告,请注意那么你应该重新考虑这个方法。

Not forgetting that if you're using a sub-report in the main report Title band for a similar purpose then you should probably re-think the approach for that as well.

如果有一个特定的原因你可以在子报告中应用相同的逻辑按照原始问题使用。当您使用主页面编号时,这也会给出正确的结果,例如您的子报告代码如下所示:

If there is a specific reason for this you can apply the same logic in a sub-report to be used as per the original question. As you are using Master page-numbering this will also give the correct results e.g. your sub-report code would look like this:

<?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>

这篇关于Jasper Reports:子报表内的页码不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆