Jasper reports 如何使用ireports添加子报表?

Jasper reports 如何使用ireports添加子报表?,jasper-reports,subreport,Jasper Reports,Subreport,我已经为主报告添加了子报告,通过从发票数据库表中获取详细信息来打印发票id、duedate和total的值。 但我无法使用参数打印字段。 请任何人都可以帮助我。我是新的贾斯珀报告设计 我的代码: <?xml version="1.0" encoding="UTF-8"?> <jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/

我已经为主报告添加了子报告,通过从发票数据库表中获取详细信息来打印发票id、duedate和total的值。 但我无法使用参数打印字段。 请任何人都可以帮助我。我是新的贾斯珀报告设计

我的代码:

<?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="Subscription_details" pageWidth="595" pageHeight="70" whenNoDataType="AllSectionsNoDetail" columnWidth="595" leftMargin="0" rightMargin="0" topMargin="0" bottomMargin="0" >
<property name="com.jasperassistant.designer.GridHeight" value="12"/>
<property name="com.jasperassistant.designer.GridWidth" value="12"/>
<property name="com.jasperassistant.designer.SnapToGrid" value="false"/>
<property name="com.jasperassistant.designer.Grid" value="false"/>
<property name="ireport.zoom" value="1.0"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="0"/>
<parameter name="customerId" class="java.lang.String"/>
<parameter name="invoiceId" class="java.lang.Integer"/>
<parameter name="totalWithTax" class="java.lang.String"/>
<parameter name="carriedBalance" class="java.lang.String"/>
<queryString>
    <![CDATA[select i.amount as amount,i.due_date as duedate,i.id as invoiceId from invoice i where i.id=$P{invoiceId};]]>
</queryString>
<field name="description" class="java.lang.String"/>
<field name="price_per_item" class="java.math.BigDecimal"/>
<field name="quantity" class="java.lang.Integer"/>
<field name="amount" class="java.math.BigDecimal"/>

<columnHeader>
    <band height="34">
        <staticText>
            <reportElement x="12" y="10" width="100" height="16" />
            <textElement>
                <font size="11" isBold="false"/>
            </textElement>
            <text><![CDATA[Racun od]]></text>
        </staticText>
        <staticText>
            <reportElement x="180" y="10" width="70" height="14" />
            <textElement>
                <font size="10" isBold="false"/>
            </textElement>
            <text><![CDATA[Nacl Pl.]]></text>
        </staticText>
        <staticText>
            <reportElement x="374" y="10" width="70" height="14" />
            <textElement>
                <font size="10" isBold="false"/>
            </textElement>
            <text><![CDATA[Iznos]]></text>
        </staticText>
        <line>
            <reportElement x="12" y="33" width="543" height="1" />
            <graphicElement>
                <pen lineWidth="0.5"/>
            </graphicElement>
        </line>
        <staticText>
            <reportElement x="263" y="12" width="100" height="14" />
            <textElement>
                <font size="10"/>
            </textElement>
            <text><![CDATA[Broj Racuna]]></text>
        </staticText>
        <staticText>
            <reportElement x="484" y="12" width="71" height="14" />
            <textElement>
                <font size="10"/>
            </textElement>
            <text><![CDATA[Otvoreno]]></text>
        </staticText>
    </band>
</columnHeader>
<detail>
    <band height="17">
        <textField>
            <reportElement x="154" y="0" width="100" height="11" >

            </reportElement>
            <textElement textAlignment="Right" verticalAlignment="Middle"/>
            <textFieldExpression><![CDATA[$P{duedate}]]></textFieldExpression>
        </textField>
    </band>
</detail>
<summary>
    <band height="20">
        <staticText>
            <reportElement x="261" y="1" width="113" height="15" forecolor="#000000" />
            <textElement textAlignment="Left" verticalAlignment="Bottom">
                <font size="10" isBold="false"/>
            </textElement>
            <text><![CDATA[Ukupno CHF . . . .
       ]]></text>
        </staticText>
        <textField>
            <reportElement x="344" y="0" width="100" height="13" >
                <printWhenExpression><![CDATA[new Boolean($F{amount}!==null)]]></printWhenExpression>
            </reportElement>
            <textElement textAlignment="Right" verticalAlignment="Middle"/>
            <textFieldExpression><![CDATA[$P{amount}]]></textFieldExpression>
        </textField>
        <line>
            <reportElement x="12" y="1" width="543" height="1" />
            <graphicElement>
                <pen lineWidth="0.5"/>
            </graphicElement>
        </line>
        <line>
            <reportElement x="254" y="17" width="301" height="1" />
            <graphicElement>
                <pen lineWidth="0.5"/>
            </graphicElement>
        </line>
    </band>
 </summary>
 </jasperReport>

向iReport添加子报表有几个步骤。我会尽力一步一步地解释

步骤:

1) 使用将在未来子报表中用作参数的值生成空报表

2) 仅将子报表元素拖动到详细信息栏中

3) 当向导弹出时-使用现有报告或创建新报告

4) 使用设计查询删除子报表中需要的字段

5) 确保使用与填写主报告相同的连接

6) 现在,在子报表上删除字段等并设计它。如果您使用“Part.num”之类的值来创建参数,则必须将其包含在初始主报告中

7) 转到主报告,单击子报告框并在属性选项卡上向下滚动。在此处可以看到“参数”字段。双击打开并点击添加。M***确保您对该参数的命名方式与在子报表***中对其命名的方式完全相同,然后只需搜索该字段并点击OK

8) 编译这两个参数,并继续对从子报表/子报表中添加或删除的每个参数执行完全相同的步骤

我希望这有帮助,如果你有任何问题,请告诉我

来源: