2017-02-06 48 views
1

我在我的应用程序中有几个类似的报告,因为这个原因,我创建了一个基本的结构,其中一个子报表内的标题和另一个内页面页脚。贾斯珀报告:子报表内的页码不起作用

问题是我有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> 

但变量PAGE_NUMBER,不工作,始终在页面显示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> 

我不知道为什么我不能找到办法解决这个,如果有人能帮助我...谢谢!

+0

的可能的复制(http://stackoverflow.com/questions/9597256/how-to-add-page [如何跨主机和子报表添加页码] - 编号跨越主和子报表)&[如何在多页PDF报表中添加页码](http://stackoverflow.com/q/14641489/876298) –

回答

1

如果您只是使用这些子报告进行页码编号,那么这就是您遇到错误的原因。这些子报告中的每一个只有1页长,所以它总是第1页的1。

通常没有必要像这样使用子报告进行页面编号,因为调用sub的开销报告的价值通常比通过这样做获得的收益更有价值。

我建议你摆脱你的子报告,并让主报告做重大举措,例如,跨越与使用主报表引擎数据的完整报告页码把你的文本字段的日期在主报表页脚,也使用页码验证码:

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

嗨,维克多,与我原来的答案相同的逻辑适用,所以我编辑它以告诉你这是一种替代方法。希望这有助于。 – philipobrien