2012-04-12 91 views
1

我是Jasper Reports的新手。我有一個2組的報告。根據查詢,正在打印多個頁面。Jasper Reports:如何在一頁中打印多個頁面

第一組高度 - 95點和第二組高度 - 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
請幫我對此。

+0

你能張貼你的屏幕截圖iReport中的報告設計? – 2012-04-12 07:46:33

+0

@Alex,它不允許我添加圖像。請找到報告設計的鏈接_http://www.flickr.com/photos/7899[email protected] – charishb4u 2012-04-12 08:31:54

回答

0

我已經根據您的規格進行了測試,它似乎工作得很好。我可以在這裏給你幾個指針。

  1. 在您的主報表設計中,只要子報表元素的高度與底層波段相同,子報表元素的高度就無關緊要。如果子報告元素較短,則結果中將出現差異。
  2. 子報告的頁高不重要,只是波段的總高度。
  3. 檢查以確保尚未在您創建的組上選擇「在新頁面上啓動」選項。這是最可能的問題。

如果前3個問題沒有解決您的問題,請查看下面的示例並比較差異。

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>