从子报告返回主报告的值

时间:2018-04-11 15:59:11

标签: jasper-reports subreport

我按照给定的步骤搜索并准备了我的样本报告。

步骤:

  1. 使用变量retval_sub创建子报表[将变量的默认值保留为Hai]

  2. 创建主报表变量retval_main。

  3. 子报告属性 - >将子报表变量添加为retval_sub,相应的主报表变量为retval_main。

  4. 我尝试了很多次但它没有工作我将计算类型保持为System and Nothing,但它不适用于两者。

    主要报告:

    <?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="testing_ret_val" language="groovy" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="5c1d1561-8eed-47a8-89c8-3cd1946ce07a">
        <parameter name="SUBREPORT_DIR" class="java.lang.String" isForPrompting="false">
            <defaultValueExpression><![CDATA["E:\\ilaiyaraja\\"]]></defaultValueExpression>
        </parameter>
        <queryString>
            <![CDATA[select * from my_table]]>
        </queryString>
        <field name="id" class="java.lang.Integer"/>
        <variable name="retval_main" class="java.lang.String" calculation="System"/>
        <detail>
            <band height="43" splitType="Stretch"/>
        </detail>
        <summary>
            <band height="226" splitType="Stretch">
                <textField>
                    <reportElement x="31" y="173" width="100" height="20" uuid="4e5ed8fa-e4f6-42bc-8651-6888d79f01b5"/>
                    <textFieldExpression><![CDATA[$V{retval_main}]]></textFieldExpression>
                </textField>
                <subreport>
                    <reportElement x="15" y="16" width="200" height="100" uuid="2bd63504-b57e-4561-b527-62f6ffe46a30"/>
                    <connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
                    <returnValue subreportVariable="retval_sub" toVariable="retval_main"/>
                    <subreportExpression><![CDATA[$P{SUBREPORT_DIR} + "testing_ret_val_subreport1.jasper"]]></subreportExpression>
                </subreport>
            </band>
        </summary>
    </jasperReport>
    

    子报告:

    <?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="testing_ret_val_subreport1" language="groovy" pageWidth="555" pageHeight="802" columnWidth="555" leftMargin="0" rightMargin="0" topMargin="0" bottomMargin="0" uuid="822d1131-8494-45f3-a9ab-39fc9a05072f">
        <queryString>
            <![CDATA[select id from my_table]]>
        </queryString>
        <field name="id" class="java.lang.Integer"/>
        <variable name="retval_sub" class="java.lang.String">
            <variableExpression><![CDATA["Hai"]]></variableExpression>
        </variable>
        <detail>
            <band height="45" splitType="Stretch">
                <textField>
                    <reportElement x="107" y="17" width="100" height="20" uuid="f8d1612a-06be-4082-b915-0df82b3faa42"/>
                    <textFieldExpression><![CDATA[$V{retval_sub}]]></textFieldExpression>
                </textField>
            </band>
        </detail>
    </jasperReport>
    

    请建议

1 个答案:

答案 0 :(得分:0)

<subreport> <reportElement x="-6" y="0" width="570" height="59" uuid="ac54a12b-8022-49a1-bc90-90cff664e3a1"/> <dataSourceExpression><![CDATA[((net.sf.jasperreports.engine.data.JsonDataSource)$P{REPORT_DATA_SOURCE}).subDataSource("footer")]]></dataSourceExpression> <subreportExpression><![CDATA["footer.jrxml"]]></subreportExpression> </subreport>

将此添加到您的代码中,它将起作用