当前位置: 首页 > 知识库问答 >
问题:

将子报表添加到 Jasper Studio 中的主报表

谈秦斩
2023-03-14

我有一个要转换成CSV格式的XML。我使用Jasper Reports来转换它,并使用Jasper Studio来设计JRXML。

这是XML:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<menu-compare xmlns:mig="http://www..com/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www..com">
    <menu-info>
        <menu type="ons" name="HCOTA"/>
        <menu type="ux" name="RTACOF"/>
    </menu-info>
    <field-details>
        <fields existence="both">
            <field name="taChrgOffMsg.taChrgOffCrit.funcCode">
                <field-type type="ons">
                    <group-name>cota</group-name>
                    <page-name>cotacrit</page-name>
                    <control-type>Combo Box</control-type>
                    <ui-field>funcCode</ui-field>
                    <label>FLT000204</label>
                    <label-desc>Function</label-desc>
                    <mandatory>Y</mandatory>
                </field-type>
                <field-type type="ux">
                    <group-name>Rtacof</group-name>
                    <page-name>Rtacof_criteria_form</page-name>
                    <page-name-desc>Transaction A/c. Details</page-name-desc>
                    <control-type>FinHidden</control-type>
                    <ui-field>funcCode</ui-field>
                    <section-structure>group1</section-structure>
                    <form>criteria</form>
                </field-type>
            </field>
            <field name="taChrgOffMsg.taChrgOffCrit.Acct.foracid">
                <field-type type="ons">
                    <group-name>cota</group-name>
                    <page-name>cotacrit</page-name>
                    <control-type>Text Field</control-type>
                    <ui-field>acctId</ui-field>
                    <label>FLT000265</label>
                    <label-desc>A/c. ID</label-desc>
                    <mandatory>Y</mandatory>
                </field-type>
                <field-type type="ux">
                    <group-name>Rtacof</group-name>
                    <page-name>Rtacof_criteria_form</page-name>
                    <page-name-desc>Transaction A/c. Details</page-name-desc>
                    <control-type>FinAccountId</control-type>
                    <ui-field>acctId$accountId</ui-field>
                    <label>FLT001251</label>
                    <label-desc>A/c. ID</label-desc>
                    <mandatory>Y</mandatory>
                    <section-structure>group1.section1.subSection1.finRow1.finCell1</section-structure>
                    <form>criteria</form>
                </field-type>
            </field>
        </fields>
        <fields existence="nonMap">
            <field>
                <field-type type="ons">
                    <group-name>cota</group-name>
                    <page-name>cotacrit</page-name>
                    <control-type>Desc. Label</control-type>
                    <ui-field>acctCrncy</ui-field>
                    <label></label>
                    <mandatory>N</mandatory>
                </field-type>
            </field>
            <field>
                <field-type type="ons">
                    <group-name>cota</group-name>
                    <page-name>cotacrit</page-name>
                    <control-type>Desc. Label</control-type>
                    <ui-field>acctSol</ui-field>
                    <label></label>
                    <mandatory>N</mandatory>
                </field-type>
            </field>
            <field>
                <field-type type="ons">
                    <group-name>cota</group-name>
                    <page-name>cotacrit</page-name>
                    <control-type>Desc. Label</control-type>
                    <ui-field>acctName</ui-field>
                    <label></label>
                    <mandatory>N</mandatory>
                </field-type>
            </field>
            <field>
                <field-type type="ux">
                    <group-name>Rtacof</group-name>
                    <page-name>Rtacof_criteria_form</page-name>
                    <page-name-desc>Transaction A/c. Details</page-name-desc>
                    <control-type>FinAccountId</control-type>
                    <ui-field>acctId</ui-field>
                    <label>FLT001251</label>
                    <label-desc>A/c. ID</label-desc>
                    <mandatory>Y</mandatory>
                    <section-structure>group1.section1.subSection1.finRow1.finCell1</section-structure>
                    <form>criteria</form>
                </field-type>
            </field>
            <field>
                <field-type type="ux">
                    <group-name>Rtacof</group-name>
                    <page-name>Rtacof_criteria_form</page-name>
                    <page-name-desc>Transaction A/c. Details</page-name-desc>
                    <control-type>FinHidden</control-type>
                    <ui-field>funcCodeExp</ui-field>
                    <section-structure>group1</section-structure>
                    <form>criteria</form>
                </field-type>
            </field>
            <field>
                <field-type type="ux">
                    <group-name>Rtacof</group-name>
                    <page-name>Rtacof_criteria_form</page-name>
                    <page-name-desc>Transaction A/c. Details</page-name-desc>
                    <control-type>FinHidden</control-type>
                    <ui-field>hchrgeOffAmt</ui-field>
                    <section-structure>group1</section-structure>
                    <form>criteria</form>
                </field-type>
            </field>
        </fields>
        <fields existence="ux">
            <field name="taChrgOffMsg.taChrgOffCrit.Acct.acctName">
                <field-type type="ux">
                    <group-name>Rtacof</group-name>
                    <page-name>Rtacof_criteria_form</page-name>
                    <page-name-desc>Transaction A/c. Details</page-name-desc>
                    <control-type>FinAccountId</control-type>
                    <ui-field>acctId$accountNameDesc</ui-field>
                    <label>FLT001251</label>
                    <label-desc>A/c. ID</label-desc>
                    <mandatory>Y</mandatory>
                    <section-structure>group1.section1.subSection1.finRow1.finCell1</section-structure>
                    <form>criteria</form>
                </field-type>
            </field>
            <field name="taChrgOffMsg.taChrgOffCrit.Acct.crncyCode">
                <field-type type="ux">
                    <group-name>Rtacof</group-name>
                    <page-name>Rtacof_criteria_form</page-name>
                    <page-name-desc>Transaction A/c. Details</page-name-desc>
                    <control-type>FinAccountId</control-type>
                    <ui-field>acctId$currencyDesc</ui-field>
                    <label>FLT001251</label>
                    <label-desc>A/c. ID</label-desc>
                    <mandatory>Y</mandatory>
                    <section-structure>group1.section1.subSection1.finRow1.finCell1</section-structure>
                    <form>criteria</form>
                </field-type>
            </field>
        </fields>
    </field-details>
</menu-compare>

我希望CSV格式包含以下列:

                                    ons(field_type)        ux(field_type)
     fields_existence field_name control-type page-name control-type page-name

fields_exitence分为3个(nonMap、ux和两者),属性在

因此,我创建了一个主报表,其中包含fields_existencefield_name以及“ons”和“ux”的两个子报表。

主报告:

<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version last-->
<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="New3" language="groovy" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="7eade40b-45a9-4626-bef7-fbcc2d4397a4">
    <property name="com.jaspersoft.studio.data.defaultdataadapter" value="New Data Adapter (5)"/>
    <subDataset name="Dataset1" uuid="5c92bcef-d33d-481e-afaa-02aa04792e45">
        <queryString>
            <![CDATA[]]>
        </queryString>
        <field name="field_name" class="java.lang.String">
            <fieldDescription><![CDATA[@name]]></fieldDescription>
        </field>
        <field name="control-type-ons" class="java.lang.String">
            <fieldDescription><![CDATA[/fields/field/field-type[@type = "ons"]/control-type]]></fieldDescription>
        </field>
        <field name="control-type-ux" class="java.lang.String">
            <fieldDescription><![CDATA[/fields/field/field-type[@type = "ux"]/control-type]]></fieldDescription>
        </field>
        <field name="control-typee-ons" class="java.lang.String">
            <fieldDescription><![CDATA[control-type]]></fieldDescription>
        </field>
        <field name="control-typee-ux" class="java.lang.String">
            <fieldDescription><![CDATA[/fields/field/field-type[@type = "ux"]/control-type]]></fieldDescription>
        </field>
        <field name="label-desc-ons" class="java.lang.String">
            <fieldDescription><![CDATA[/fields/field/field-type[@type = "ons"]/label-desc]]></fieldDescription>
        </field>
    </subDataset>
    <subDataset name="Dataset2" uuid="f8c00177-6263-49fc-b17d-f307080a8539">
        <queryString>
            <![CDATA[]]>
        </queryString>
        <field name="control-type_d2_ons" class="java.lang.String">
            <fieldDescription><![CDATA[control-type]]></fieldDescription>
        </field>
    </subDataset>
    <queryString language="XPath">
        <![CDATA[/menu-compare/field-details/fields]]>
    </queryString>
    <field name="fields_exists" class="java.lang.String">
        <fieldDescription><![CDATA[@existence]]></fieldDescription>
    </field>
    <field name="field" class="java.lang.String">
        <fieldDescription><![CDATA[field]]></fieldDescription>
    </field>
    <field name="field_1" class="java.lang.String">
        <fieldDescription><![CDATA[field]]></fieldDescription>
    </field>
    <field name="field_2" class="java.lang.String">
        <fieldDescription><![CDATA[field]]></fieldDescription>
    </field>
    <field name="field_3" class="java.lang.String">
        <fieldDescription><![CDATA[field]]></fieldDescription>
    </field>
    <field name="field_4" class="java.lang.String">
        <fieldDescription><![CDATA[field]]></fieldDescription>
    </field>
    <field name="field_5" class="java.lang.String">
        <fieldDescription><![CDATA[field]]></fieldDescription>
    </field>
    <background>
        <band splitType="Stretch"/>
    </background>
    <title>
        <band height="79" splitType="Stretch"/>
    </title>
    <pageHeader>
        <band height="35" splitType="Stretch"/>
    </pageHeader>
    <columnHeader>
        <band height="73" splitType="Stretch">
            <textField>
                <reportElement uuid="a7807abf-6697-4dbb-b990-f4a63572c158" x="10" y="30" width="70" height="30"/>
                <textElement/>
                <textFieldExpression><![CDATA["Map_Type"]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement uuid="fe9d6fa6-30c2-4507-867a-f60d872a4002" x="110" y="30" width="70" height="30"/>
                <textElement/>
                <textFieldExpression><![CDATA["Field-Name"]]></textFieldExpression>
            </textField>
        </band>
    </columnHeader>
    <detail>
        <band height="264" splitType="Stretch">
            <textField>
                <reportElement uuid="3f1e6c53-cb80-4117-9aeb-c5b26b1169c0" x="10" y="10" width="70" height="30"/>
                <textElement/>
                <textFieldExpression><![CDATA[$F{fields_exists}]]></textFieldExpression>
            </textField>
            <componentElement>
                <reportElement uuid="e888d323-d870-4c8d-9826-2930dbafcaa4" x="100" y="10" width="310" height="60"/>
                <jr:list xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd" printOrder="Vertical">
                    <datasetRun subDataset="Dataset1" uuid="fba9150e-05b0-4c8d-933f-26e4766a1de4">
                        <dataSourceExpression><![CDATA[$P{REPORT_DATA_SOURCE}.subDataSource("/fields/field")]]></dataSourceExpression>
                    </datasetRun>
                    <jr:listContents height="66" width="310">
                        <textField>
                            <reportElement uuid="6fb1b0ce-65f2-4c22-aa27-f4083bb535c2" x="10" y="15" width="70" height="30"/>
                            <textElement/>
                            <textFieldExpression><![CDATA[$F{field_name}]]></textFieldExpression>
                        </textField>
                        <textField>
                            <reportElement uuid="c1821c08-9cdd-4ab2-81d1-6e7981f755fe" x="100" y="15" width="70" height="30"/>
                            <textElement/>
                            <textFieldExpression><![CDATA[$F{control-type-ons}]]></textFieldExpression>
                        </textField>
                        <textField>
                            <reportElement uuid="c5cd28df-0742-4f4b-ae5d-1098b472b5a0" x="200" y="15" width="70" height="30"/>
                            <textElement/>
                            <textFieldExpression><![CDATA[$F{control-type-ux}]]></textFieldExpression>
                        </textField>
                    </jr:listContents>
                </jr:list>
            </componentElement>
            <subreport>
                <reportElement uuid="e57583f2-7163-4c8b-8245-7586cf22491f" x="440" y="20" width="41" height="46"/>
                <dataSourceExpression><![CDATA[$P{REPORT_DATA_SOURCE}.subDataSource("/fields/field/field-type")]]></dataSourceExpression>
                <subreportExpression><![CDATA["New3_SubReport_Ons.jasper"]]></subreportExpression>
            </subreport>
        </band>
    </detail>
    <columnFooter>
        <band height="45" splitType="Stretch"/>
    </columnFooter>
    <pageFooter>
        <band height="54" splitType="Stretch"/>
    </pageFooter>
    <summary>
        <band height="42" splitType="Stretch"/>
    </summary>
</jasperReport>

SubReport_ONS :在这里我正确获取数据,填充了下面列出的所有字段属性。但是当我将其添加到主报告中时,没有任何内容被填充。

<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version last-->
<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="New3_SubReport_Ons" language="groovy" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="7d9c4551-de86-4504-9dc0-b7617a01f620">
    <property name="com.jaspersoft.studio.data.defaultdataadapter" value="New Data Adapter (5)"/>
    <queryString language="xPath">
        <![CDATA[/menu-compare/field-details/fields/field/field-type[@type = "ons"]]]>
    </queryString>
    <field name="group-name" class="java.lang.String">
        <fieldDescription><![CDATA[group-name]]></fieldDescription>
    </field>
    <field name="page-name" class="java.lang.String">
        <fieldDescription><![CDATA[page-name]]></fieldDescription>
    </field>
    <field name="control-type" class="java.lang.String">
        <fieldDescription><![CDATA[control-type]]></fieldDescription>
    </field>
    <field name="ui-field" class="java.lang.String">
        <fieldDescription><![CDATA[ui-field]]></fieldDescription>
    </field>
    <field name="label" class="java.lang.String">
        <fieldDescription><![CDATA[label]]></fieldDescription>
    </field>
    <field name="label-desc" class="java.lang.String">
        <fieldDescription><![CDATA[label-desc]]></fieldDescription>
    </field>
    <field name="mandatory" class="java.lang.String">
        <fieldDescription><![CDATA[mandatory]]></fieldDescription>
    </field>
    <field name="section-structure" class="java.lang.String">
        <fieldDescription><![CDATA[section-structure]]></fieldDescription>
    </field>
    <field name="form" class="java.lang.String">
        <fieldDescription><![CDATA[form]]></fieldDescription>
    </field>
    <background>
        <band splitType="Stretch"/>
    </background>
    <columnHeader>
        <band height="74" splitType="Stretch">
            <textField>
                <reportElement uuid="11e36190-331d-492d-b2f8-b6b5e255ad29" x="0" y="30" width="70" height="30"/>
                <textElement/>
                <textFieldExpression><![CDATA["control-type"]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement uuid="d29aaacd-1eb0-4f18-800f-79745afaab6a" x="80" y="30" width="70" height="30"/>
                <textElement/>
                <textFieldExpression><![CDATA["label-desc"]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement uuid="975c7937-8450-4270-a14c-f04906402a8a" x="160" y="30" width="70" height="30"/>
                <textElement/>
                <textFieldExpression><![CDATA["label"]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement uuid="29fd8188-114b-4731-8b44-e1b8b87b5734" x="242" y="30" width="70" height="30"/>
                <textElement/>
                <textFieldExpression><![CDATA["ui-field"]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement uuid="8f51cdc4-c1ce-4337-ab61-f4d43d4646bc" x="320" y="30" width="70" height="30"/>
                <textElement/>
                <textFieldExpression><![CDATA["group-name"]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement uuid="7f31617e-3683-4693-a248-6bebe0f5bdf5" x="400" y="30" width="70" height="30"/>
                <textElement/>
                <textFieldExpression><![CDATA["page-name"]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement uuid="24846d3e-7179-4fc7-91e2-f087b35676ac" x="490" y="30" width="70" height="30"/>
                <textElement/>
                <textFieldExpression><![CDATA["mandatory"]]></textFieldExpression>
            </textField>
        </band>
    </columnHeader>
    <detail>
        <band height="125" splitType="Stretch">
            <textField>
                <reportElement uuid="24c09848-f19d-4954-94d9-f6b1cb95f968" x="0" y="20" width="70" height="30"/>
                <textElement/>
                <textFieldExpression><![CDATA[$F{control-type}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement uuid="ab6c2cb7-8591-46e4-900e-4b60e0f08f21" x="80" y="20" width="70" height="30"/>
                <textElement/>
                <textFieldExpression><![CDATA[$F{label-desc}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement uuid="ab1ff84a-23b9-44c1-88a6-1c5a9fffaeb5" x="160" y="20" width="70" height="30"/>
                <textElement/>
                <textFieldExpression><![CDATA[$F{label}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement uuid="acfb12b3-d8e0-4319-9339-182ac90a5e8b" x="242" y="20" width="70" height="30"/>
                <textElement/>
                <textFieldExpression><![CDATA[$F{ui-field}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement uuid="1e0c29fd-e910-40dc-b67b-57aabcf96726" x="320" y="20" width="70" height="30"/>
                <textElement/>
                <textFieldExpression><![CDATA[$F{group-name}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement uuid="f37a62d2-2dfe-4f97-b60e-6fc2cf7e868c" x="400" y="20" width="70" height="30"/>
                <textElement/>
                <textFieldExpression><![CDATA[$F{page-name}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement uuid="084363d8-635f-4d8b-b0d2-01dbca4ff39f" x="490" y="20" width="70" height="30"/>
                <textElement/>
                <textFieldExpression><![CDATA[$F{mandatory}]]></textFieldExpression>
            </textField>
        </band>
    </detail>
</jasperReport>

共有1个答案

凌俊材
2023-03-14

尝试在JasperReports服务器上发布您的报告,然后运行主报告....主要思想是JasperSoft Studio没有给我们精确的报告执行,一些主题必须在JasperReports服务器中实现和执行,以检查我们工作的成功或错误......我希望它对您有所帮助,最好的问候。

 类似资料:
  • 目前,我正在使用JasperReports和DynamicJasper构建我的报告并打印它们。当我只使用单个jasper-files或jrxml-files时,所有的工作都很好。我还有一段代码,如果需要合并报表,它可以将所有JasperPrint-files合并为一个。然而,这并不是最理想的... 我可以使用一个.jasper或.jrxml文件作为主报表(它有一个页眉、一个页脚和n个空的详细信息带

  • 我已经创建了一个Jasper报告,我正试图将报告集成到主报告中。我可以按原样填充子报表中的数据,但如果我将其集成到主报表中,我就不能呈现我在子报表中呈现的数据。事实上,我在集成子报表的地方得到了空白。

  • 使用的开发IDE:Jaspersoft Studio 我试图使用下面的表达式将主报表数据源用于表数据集,但没有得到任何数据。 请说明如何将数据源从报表传递到表。我对jasper报告很陌生。样品会很有用。 JRXML: Json数据: 我已经添加了我试图加载的JRXML和Json。当我在数据集中传递dataSourceExpression时,我只得到2行,但在源数据中有3行。请帮我解决这个问题

  • 我已经创建了表的结构,在第2页中,源数据是一个JSON,包含产品及其属性列表。我想将JSON数据显示到表中,实际上有一个包含表的子报表,但不知道如何将JSON数据传递到子报表,并根据JSON数据中的productList键进行填充。报告从接收用户数据的java类填充。 我不知道如何填写第 2 页的表格,有人可以帮助我吗? 这是我在Jaspersoft Studio 6.10中的代码 主报告 子报表

  • 我将页码信息从主报表传递到页脚子报表。在主报表中,我已经声明了子报表参数pageTot和pageNum。它们通过向导映射到主报告$V{PAGE _ COUNT}和$V{PAGE _ NUMBER}中的参数。在子报表中,我声明了两个参数pageNum和pageTot。在它们的参数属性中,我取消了将use作为提示,并将它们都设置为java.lang.integer类型。然后,我替换了文本字段的文本字段