Jasper Reports:如何在一个页面中打印多个页面

时间:2012-04-12 06:01:19

标签: jasper-reports ireport

我是Jasper Reports的新手。我有两组报告。根据查询,正在打印多个页面。

第1组身高 - 95分和第2组身高 - 144分

我希望在一个页面中打印这些多个页面(我想在页面中合并5个页面)。每页的高度为239点。 (即使页面内容小于239分,我也希望将剩余部分保留为空白,并在239分之后开始下一页)。我尝试创建报告并将上述报告作为子报告包含在内,并将主报告的高度设置为1195(239 * 5)点。不过,这些都是以不同的页面打印出来的。

出口的结果是: Report looks like this when it is printed

主要报告设计是: Main Report - This is including 2 subreports

第一个子报告设计是: First SubReport

第二个子报告设计是: Second SubReport
请帮我解决这个问题。

1 个答案:

答案 0 :(得分:0)

我根据您的规格进行了测试,似乎工作正常。我可以在这里给你几点指示。

  1. 在主报表设计中,子报表元素的高度无关紧要,只要它等于基础频段即可。如果子报表元素较短,则差异将显示在结果中。
  2. 子报告的页面高度无关紧要,只是乐队的总高度。
  3. 检查以确保未在您创建的组中选择“在新页面上开始”选项。这是最有可能发生的问题。
  4. 如果前三名没有解决您的问题,请查看下面的示例并比较差异。

    <强> MainReport:

    <?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="MainReport1" language="groovy" pageWidth="595" pageHeight="1195" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="0" bottomMargin="0">
        <property name="ireport.zoom" value="1.0"/>
        <property name="ireport.x" value="0"/>
        <property name="ireport.y" value="0"/>
        <parameter name="SUBREPORT_DIR" class="java.lang.String" isForPrompting="false">
            <defaultValueExpression><![CDATA["C:\\Users\\Bizz\\Documents\\JasperReports\\"]]></defaultValueExpression>
        </parameter>
        <queryString>
            <![CDATA[SELECT
         PRODUCT."ID" AS PRODUCT_ID,
         PRODUCT."NAME" AS PRODUCT_NAME,
         PRODUCT."COST" AS PRODUCT_COST
    FROM
         "PUBLIC"."PRODUCT" PRODUCT]]>
        </queryString>
        <field name="PRODUCT_ID" class="java.lang.Integer"/>
        <field name="PRODUCT_NAME" class="java.lang.String"/>
        <field name="PRODUCT_COST" class="java.math.BigDecimal"/>
        <group name="Group1">
            <groupExpression><![CDATA[$F{PRODUCT_ID}]]></groupExpression>
            <groupHeader>
                <band height="50">
                    <subreport>
                        <reportElement x="0" y="0" width="200" height="50"/>
                        <subreportParameter name="ProductID">
                            <subreportParameterExpression><![CDATA[$F{PRODUCT_ID}]]></subreportParameterExpression>
                        </subreportParameter>
                        <connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
                        <subreportExpression><![CDATA[$P{SUBREPORT_DIR} + "MainReport1_subreport2.jasper"]]></subreportExpression>
                    </subreport>
                </band>
            </groupHeader>
        </group>
        <group name="Group2">
            <groupExpression><![CDATA["2"]]></groupExpression>
            <groupHeader>
                <band height="50">
                    <subreport>
                        <reportElement x="0" y="0" width="200" height="50"/>
                        <subreportParameter name="ProductID">
                            <subreportParameterExpression><![CDATA[$F{PRODUCT_ID}]]></subreportParameterExpression>
                        </subreportParameter>
                        <connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
                        <subreportExpression><![CDATA[$P{SUBREPORT_DIR} + "MainReport1_subreport1.jasper"]]></subreportExpression>
                    </subreport>
                </band>
            </groupHeader>
        </group>
        <background>
            <band splitType="Stretch"/>
        </background>
        <title>
            <band splitType="Stretch"/>
        </title>
        <pageHeader>
            <band splitType="Stretch"/>
        </pageHeader>
        <columnHeader>
            <band splitType="Stretch"/>
        </columnHeader>
        <detail>
            <band splitType="Stretch"/>
        </detail>
        <columnFooter>
            <band splitType="Stretch"/>
        </columnFooter>
        <pageFooter>
            <band splitType="Stretch"/>
        </pageFooter>
        <summary>
            <band splitType="Stretch"/>
        </summary>
    </jasperReport>
    

    <强> Subreport1:

    <?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="MainReport1_subreport1" language="groovy" pageWidth="555" pageHeight="95" columnWidth="555" leftMargin="0" rightMargin="0" topMargin="0" bottomMargin="0">
        <property name="ireport.zoom" value="1.0"/>
        <property name="ireport.x" value="0"/>
        <property name="ireport.y" value="0"/>
        <parameter name="ProductID" class="java.lang.Integer"/>
        <queryString>
            <![CDATA[SELECT
         PRODUCT."ID" AS PRODUCT_ID,
         PRODUCT."NAME" AS PRODUCT_NAME,
         PRODUCT."COST" AS PRODUCT_COST
    FROM
         "PUBLIC"."PRODUCT" PRODUCT
    where
      product_id = $P{ProductID}]]>
        </queryString>
        <field name="PRODUCT_ID" class="java.lang.Integer"/>
        <field name="PRODUCT_NAME" class="java.lang.String"/>
        <field name="PRODUCT_COST" class="java.math.BigDecimal"/>
        <background>
            <band splitType="Stretch"/>
        </background>
        <title>
            <band splitType="Stretch"/>
        </title>
        <pageHeader>
            <band splitType="Stretch"/>
        </pageHeader>
        <columnHeader>
            <band splitType="Stretch"/>
        </columnHeader>
        <detail>
            <band height="95" splitType="Stretch">
                <staticText>
                    <reportElement x="0" y="0" width="100" height="20"/>
                    <textElement/>
                    <text><![CDATA[PRODUCT_ID]]></text>
                </staticText>
                <textField>
                    <reportElement x="100" y="0" width="100" height="20"/>
                    <textElement/>
                    <textFieldExpression><![CDATA[$F{PRODUCT_ID}]]></textFieldExpression>
                </textField>
                <staticText>
                    <reportElement x="0" y="20" width="100" height="20"/>
                    <textElement/>
                    <text><![CDATA[PRODUCT_NAME]]></text>
                </staticText>
                <textField>
                    <reportElement x="100" y="20" width="100" height="20"/>
                    <textElement/>
                    <textFieldExpression><![CDATA[$F{PRODUCT_NAME}]]></textFieldExpression>
                </textField>
                <staticText>
                    <reportElement x="0" y="40" width="100" height="20"/>
                    <textElement/>
                    <text><![CDATA[PRODUCT_COST]]></text>
                </staticText>
                <textField>
                    <reportElement x="100" y="40" width="100" height="20"/>
                    <textElement/>
                    <textFieldExpression><![CDATA[$F{PRODUCT_COST}]]></textFieldExpression>
                </textField>
                <componentElement>
                    <reportElement x="0" y="60" width="200" height="35"/>
                    <jr:barbecue xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd" type="3of9" drawText="false" checksumRequired="false">
                        <jr:codeExpression><![CDATA[$F{PRODUCT_ID}]]></jr:codeExpression>
                    </jr:barbecue>
                </componentElement>
            </band>
        </detail>
        <columnFooter>
            <band splitType="Stretch"/>
        </columnFooter>
        <pageFooter>
            <band splitType="Stretch"/>
        </pageFooter>
        <summary>
            <band splitType="Stretch"/>
        </summary>
    </jasperReport>
    

    <强> Subreport2:

    <?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="MainReport1_subreport2" language="groovy" pageWidth="555" pageHeight="888" columnWidth="555" leftMargin="0" rightMargin="0" topMargin="0" bottomMargin="0">
        <property name="ireport.zoom" value="1.0"/>
        <property name="ireport.x" value="0"/>
        <property name="ireport.y" value="0"/>
        <parameter name="ProductID" class="java.lang.Integer"/>
        <queryString>
            <![CDATA[SELECT
         PRODUCT."ID" AS PRODUCT_ID,
         PRODUCT."NAME" AS PRODUCT_NAME,
         PRODUCT."COST" AS PRODUCT_COST
    FROM
         "PUBLIC"."PRODUCT" PRODUCT
    where
      product_id = $P{ProductID}]]>
        </queryString>
        <field name="PRODUCT_ID" class="java.lang.Integer"/>
        <field name="PRODUCT_NAME" class="java.lang.String"/>
        <field name="PRODUCT_COST" class="java.math.BigDecimal"/>
        <background>
            <band splitType="Stretch"/>
        </background>
        <title>
            <band splitType="Stretch"/>
        </title>
        <pageHeader>
            <band splitType="Stretch"/>
        </pageHeader>
        <columnHeader>
            <band splitType="Stretch"/>
        </columnHeader>
        <detail>
            <band height="144" splitType="Stretch">
                <staticText>
                    <reportElement x="0" y="0" width="100" height="20"/>
                    <textElement/>
                    <text><![CDATA[PRODUCT_ID]]></text>
                </staticText>
                <textField>
                    <reportElement x="100" y="0" width="100" height="20"/>
                    <textElement/>
                    <textFieldExpression><![CDATA[$F{PRODUCT_ID}]]></textFieldExpression>
                </textField>
                <staticText>
                    <reportElement x="0" y="20" width="100" height="20"/>
                    <textElement/>
                    <text><![CDATA[PRODUCT_NAME]]></text>
                </staticText>
                <textField>
                    <reportElement x="100" y="20" width="100" height="20"/>
                    <textElement/>
                    <textFieldExpression><![CDATA[$F{PRODUCT_NAME}]]></textFieldExpression>
                </textField>
                <staticText>
                    <reportElement x="0" y="40" width="100" height="20"/>
                    <textElement/>
                    <text><![CDATA[PRODUCT_COST]]></text>
                </staticText>
                <textField>
                    <reportElement x="100" y="40" width="100" height="20"/>
                    <textElement/>
                    <textFieldExpression><![CDATA[$F{PRODUCT_COST}]]></textFieldExpression>
                </textField>
                <componentElement>
                    <reportElement x="0" y="60" width="302" height="84"/>
                    <jr:barbecue xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd" type="3of9" drawText="false" checksumRequired="false">
                        <jr:codeExpression><![CDATA[$F{PRODUCT_ID}]]></jr:codeExpression>
                    </jr:barbecue>
                </componentElement>
            </band>
        </detail>
        <columnFooter>
            <band splitType="Stretch"/>
        </columnFooter>
        <pageFooter>
            <band splitType="Stretch"/>
        </pageFooter>
        <summary>
            <band splitType="Stretch"/>
        </summary>
    </jasperReport>