我已經根據您的規格進行了測試,它似乎工作得很好。我可以在這裏給你幾個指針。
- 在您的主報表設計中,只要子報表元素的高度與底層波段相同,子報表元素的高度就無關緊要。如果子報告元素較短,則結果中將出現差異。
- 子報告的頁高不重要,只是波段的總高度。
- 檢查以確保尚未在您創建的組上選擇「在新頁面上啓動」選項。這是最可能的問題。
如果前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>
你能張貼你的屏幕截圖iReport中的報告設計? – 2012-04-12 07:46:33
@Alex,它不允許我添加圖像。請找到報告設計的鏈接_http://www.flickr.com/photos/7899[email protected] – charishb4u 2012-04-12 08:31:54