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

将主报表数据用于Jasper报表中的表

薛文斌
2023-03-14

使用的开发IDE:Jaspersoft Studio

我试图使用下面的表达式将主报表数据源用于表数据集,但没有得到任何数据。

请说明如何将数据源从报表传递到表。我对jasper报告很陌生。样品会很有用。

JRXML:

<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.2.1.final using JasperReports Library version 6.2.1  -->
<!-- 2017-07-18T10:42:15 -->
<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="Blank_A4" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="62118ef8-810f-4b01-a13c-46539c328b0e">
        <property name="com.jaspersoft.studio.data.defaultdataadapter" value="LendingTrustFee1_3_Json"/>
        <style name="Title" fontName="Arial Unicode MS" fontSize="14"/>
        <style name="SubTitle" forecolor="#736343" fontName="Arial Unicode MS" fontSize="11"/>
        <style name="Column header" forecolor="#666666" fontName="Arial Unicode MS" fontSize="11"/>
        <style name="Detail" fontName="Arial Unicode MS" fontSize="11" pdfEncoding="Identity-H"/>
        <style name="Table_TH" mode="Opaque" backcolor="#FFFFFF">
            <box>
                <pen lineWidth="0.5" lineColor="#000000"/>
                <topPen lineWidth="0.5" lineColor="#000000"/>
                <leftPen lineWidth="0.5" lineColor="#000000"/>
                <bottomPen lineWidth="0.5" lineColor="#000000"/>
                <rightPen lineWidth="0.5" lineColor="#000000"/>
            </box>
        </style>
        <style name="Table_CH" mode="Opaque" backcolor="#FFFFFF">
            <box>
                <pen lineWidth="0.5" lineColor="#000000"/>
                <topPen lineWidth="0.5" lineColor="#000000"/>
                <leftPen lineWidth="0.5" lineColor="#000000"/>
                <bottomPen lineWidth="0.5" lineColor="#000000"/>
                <rightPen lineWidth="0.5" lineColor="#000000"/>
            </box>
        </style>
        <style name="Table_TD" mode="Opaque" backcolor="#FFFFFF">
            <box>
                <pen lineWidth="0.5" lineColor="#000000"/>
                <topPen lineWidth="0.5" lineColor="#000000"/>
                <leftPen lineWidth="0.5" lineColor="#000000"/>
                <bottomPen lineWidth="0.5" lineColor="#000000"/>
                <rightPen lineWidth="0.5" lineColor="#000000"/>
            </box>
        </style>
        <style name="Table 1_TH" mode="Opaque" backcolor="#FFFFFF">
            <box>
                <pen lineWidth="0.5" lineColor="#000000"/>
                <topPen lineWidth="0.5" lineColor="#000000"/>
                <leftPen lineWidth="0.5" lineColor="#000000"/>
                <bottomPen lineWidth="0.5" lineColor="#000000"/>
                <rightPen lineWidth="0.5" lineColor="#000000"/>
            </box>
        </style>
        <style name="Table 2_TH" mode="Opaque" backcolor="#F0F8FF">
            <box>
                <pen lineWidth="0.5" lineColor="#000000"/>
                <topPen lineWidth="0.5" lineColor="#000000"/>
                <leftPen lineWidth="0.5" lineColor="#000000"/>
                <bottomPen lineWidth="0.5" lineColor="#000000"/>
                <rightPen lineWidth="0.5" lineColor="#000000"/>
            </box>
        </style>
        <style name="Table 3_TH" mode="Opaque" backcolor="#FFFFFF">
            <box>
                <pen lineWidth="0.5" lineColor="#000000"/>
                <topPen lineWidth="0.5" lineColor="#000000"/>
                <leftPen lineWidth="0.5" lineColor="#000000"/>
                <bottomPen lineWidth="0.5" lineColor="#000000"/>
                <rightPen lineWidth="0.5" lineColor="#000000"/>
            </box>
        </style>
        <style name="Table 3_CH" mode="Opaque" backcolor="#FFFFFF">
            <box>
                <pen lineWidth="0.5" lineColor="#000000"/>
                <topPen lineWidth="0.5" lineColor="#000000"/>
                <leftPen lineWidth="0.5" lineColor="#000000"/>
                <bottomPen lineWidth="0.5" lineColor="#000000"/>
                <rightPen lineWidth="0.5" lineColor="#000000"/>
            </box>
        </style>
        <style name="Table 3_TD" mode="Opaque" backcolor="#FFFFFF">
            <box>
                <pen lineWidth="0.5" lineColor="#000000"/>
                <topPen lineWidth="0.5" lineColor="#000000"/>
                <leftPen lineWidth="0.5" lineColor="#000000"/>
                <bottomPen lineWidth="0.5" lineColor="#000000"/>
                <rightPen lineWidth="0.5" lineColor="#000000"/>
            </box>
        </style>
        <subDataset name="TableDataset" uuid="b931bf1c-7487-4583-8af0-254967fef65f">
            <queryString language="csv">
                <![CDATA[]]>
            </queryString>
            <field name="ClientAndBenificiary" class="java.lang.String">
                <fieldDescription><![CDATA[ClientAndBenificiary]]></fieldDescription>
            </field>
            <field name="DepartmentNameOfLender" class="java.lang.String">
                <fieldDescription><![CDATA[DepartmentNameOfLender]]></fieldDescription>
            </field>
            <field name="TrustNoJapanese" class="java.lang.String">
                <fieldDescription><![CDATA[TrustNoJapanese]]></fieldDescription>
            </field>
            <field name="ContractSignDate" class="java.sql.Date">
                <fieldDescription><![CDATA[ContractSignDate]]></fieldDescription>
            </field>
            <field name="TrustNo" class="java.lang.String">
                <fieldDescription><![CDATA[TrustNo]]></fieldDescription>
            </field>
            <field name="ReportStartDate" class="java.sql.Date">
                <fieldDescription><![CDATA[ReportStartDate]]></fieldDescription>
            </field>
            <field name="EndStartDate" class="java.sql.Date">
                <fieldDescription><![CDATA[EndStartDate]]></fieldDescription>
            </field>
            <field name="ReportPeriod" class="java.lang.String">
                <fieldDescription><![CDATA[ReportPeriod]]></fieldDescription>
            </field>
            <field name="Currency" class="java.lang.String">
                <fieldDescription><![CDATA[Currency]]></fieldDescription>
            </field>
            <field name="ShowLoanValue" class="java.lang.Boolean">
                <fieldDescription><![CDATA[ShowLoanValue]]></fieldDescription>
            </field>
            <field name="ShowCleanPrice" class="java.lang.Boolean">
                <fieldDescription><![CDATA[ShowCleanPrice]]></fieldDescription>
            </field>
            <field name="ShowAccruedInt" class="java.lang.Boolean">
                <fieldDescription><![CDATA[ShowAccruedInt]]></fieldDescription>
            </field>
            <field name="ShowDirtyPrice" class="java.lang.Boolean">
                <fieldDescription><![CDATA[ShowDirtyPrice]]></fieldDescription>
            </field>
            <field name="UDF1" class="java.lang.String">
                <fieldDescription><![CDATA[UDF1]]></fieldDescription>
            </field>
            <field name="UDF2" class="java.lang.String">
                <fieldDescription><![CDATA[UDF2]]></fieldDescription>
            </field>
            <field name="ReportFrequency" class="java.lang.String">
                <fieldDescription><![CDATA[ReportFrequency]]></fieldDescription>
            </field>
            <field name="QtrReportStartDate" class="java.sql.Date">
                <fieldDescription><![CDATA[QtrReportStartDate]]></fieldDescription>
            </field>
            <field name="QtrReportEndDate" class="java.sql.Date">
                <fieldDescription><![CDATA[QtrReportEndDate]]></fieldDescription>
            </field>
            <field name="Securities_No_Mon1_3" class="java.lang.String">
                <fieldDescription><![CDATA[Securities_No_Mon1_3]]></fieldDescription>
            </field>
            <field name="Lending_Fee_Mon1_3" class="java.math.BigDecimal">
                <fieldDescription><![CDATA[Lending_Fee_Mon1_3]]></fieldDescription>
            </field>
            <field name="Trust_Fee_Mon1_3" class="java.math.BigDecimal">
                <fieldDescription><![CDATA[Trust_Fee_Mon1_3]]></fieldDescription>
            </field>
            <field name="Consumption_Tax_Mon1_3" class="java.math.BigDecimal">
                <fieldDescription><![CDATA[Consumption_Tax_Mon1_3]]></fieldDescription>
            </field>
            <field name="Trust_Fee_Tax_Included_Mon1_3" class="java.math.BigDecimal">
                <fieldDescription><![CDATA[Trust_Fee_Tax_Included_Mon1_3]]></fieldDescription>
            </field>
            <field name="SectionType" class="java.lang.String">
                <fieldDescription><![CDATA[SectionType]]></fieldDescription>
            </field>
            <filterExpression><![CDATA[LEN($F{Securities_No_Mon1_3}) > 0]]></filterExpression>
        </subDataset>
        <queryString>
            <![CDATA[]]>
        </queryString>
        <background>
            <band splitType="Stretch"/>
        </background>
        <detail>
            <band height="322" splitType="Stretch">
                <componentElement>
                    <reportElement x="-1" y="0" width="551" height="220" uuid="3aaf3c11-1464-432e-a55d-fef0a54cfdaa">
                        <property name="com.jaspersoft.studio.layout" value="com.jaspersoft.studio.editor.layout.VerticalRowLayout"/>
                        <property name="com.jaspersoft.studio.table.style.table_header" value="Table 3_TH"/>
                        <property name="com.jaspersoft.studio.table.style.column_header" value="Table 3_CH"/>
                        <property name="com.jaspersoft.studio.table.style.detail" value="Table 3_TD"/>
                    </reportElement>
                    <jr:table xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd">
                        <datasetRun subDataset="TableDataset" uuid="75b0fbb9-805b-4e97-86e2-9a2688aae1ff">
                            <dataSourceExpression><![CDATA[$P{REPORT_DATA_SOURCE}]]></dataSourceExpression>
                        </datasetRun>
                        <jr:column width="90" uuid="21ee4add-5a78-4c46-8ae3-1da6c6759a19">
                            <property name="com.jaspersoft.studio.components.table.model.column.name" value="Column1"/>
                            <jr:detailCell style="Table 3_TD" height="30">
                                <textField>
                                    <reportElement style="Detail" positionType="Float" x="0" y="0" width="90" height="30" uuid="575908d3-6ea1-4a84-a95c-985941866a21"/>
                                    <box>
                                        <topPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
                                        <leftPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
                                        <bottomPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
                                        <rightPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
                                    </box>
                                    <textElement textAlignment="Center" verticalAlignment="Middle"/>
                                    <textFieldExpression><![CDATA[$F{Securities_No_Mon1_3}]]></textFieldExpression>
                                </textField>
                            </jr:detailCell>
                        </jr:column>
                        <jr:column width="90" uuid="b5f25971-4c63-4094-ab6a-102adb70593e">
                            <property name="com.jaspersoft.studio.components.table.model.column.name" value="Column2"/>
                            <jr:detailCell style="Table 3_TD" height="30">
                                <textField>
                                    <reportElement style="Detail" positionType="Float" x="0" y="0" width="90" height="30" uuid="aa37293c-1ffc-48d3-a3f2-32abc83ebcb8"/>
                                    <box>
                                        <topPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
                                        <leftPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
                                        <bottomPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
                                        <rightPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
                                    </box>
                                    <textElement textAlignment="Right" verticalAlignment="Middle"/>
                                    <textFieldExpression><![CDATA[$F{Lending_Fee_Mon1_3}]]></textFieldExpression>
                                </textField>
                            </jr:detailCell>
                        </jr:column>
                        <jr:column width="80" uuid="96b8c9f2-b20f-4850-8702-aa4935cd496f">
                            <property name="com.jaspersoft.studio.components.table.model.column.name" value="Column3"/>
                            <jr:detailCell style="Table 3_TD" height="30">
                                <textField>
                                    <reportElement style="Detail" positionType="Float" x="0" y="0" width="80" height="30" uuid="0c059aad-8bf2-45c7-854f-c26bcdcbcb72"/>
                                    <box>
                                        <topPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
                                        <leftPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
                                        <bottomPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
                                        <rightPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
                                    </box>
                                    <textElement textAlignment="Right" verticalAlignment="Middle"/>
                                    <textFieldExpression><![CDATA[$F{Trust_Fee_Mon1_3}]]></textFieldExpression>
                                </textField>
                            </jr:detailCell>
                        </jr:column>
                        <jr:column width="70" uuid="4c69cb0c-bcd8-46a5-9ccc-f284fa037f14">
                            <property name="com.jaspersoft.studio.components.table.model.column.name" value="Column4"/>
                            <jr:detailCell style="Table 3_TD" height="30">
                                <textField>
                                    <reportElement style="Detail" positionType="Float" x="0" y="0" width="70" height="30" uuid="89d56faf-0773-4b1b-9229-08e2322e7650"/>
                                    <box>
                                        <topPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
                                        <leftPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
                                        <bottomPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
                                        <rightPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
                                    </box>
                                    <textElement textAlignment="Right" verticalAlignment="Middle"/>
                                    <textFieldExpression><![CDATA[$F{Consumption_Tax_Mon1_3}]]></textFieldExpression>
                                </textField>
                            </jr:detailCell>
                        </jr:column>
                        <jr:column width="170" uuid="1ff92af5-e2c2-4ab9-864a-73496dec702d">
                            <property name="com.jaspersoft.studio.components.table.model.column.name" value="Column5"/>
                            <jr:detailCell style="Table 3_TD" height="30">
                                <textField>
                                    <reportElement style="Detail" positionType="Float" x="0" y="0" width="170" height="30" uuid="1ecb2036-49d9-4337-b1de-2aa660e15bd6"/>
                                    <box>
                                        <topPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
                                        <leftPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
                                        <bottomPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
                                        <rightPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
                                    </box>
                                    <textElement textAlignment="Right" verticalAlignment="Middle"/>
                                    <textFieldExpression><![CDATA[$F{Trust_Fee_Tax_Included_Mon1_3}]]></textFieldExpression>
                                </textField>
                            </jr:detailCell>
                        </jr:column>
                    </jr:table>
                </componentElement>
            </band>
        </detail>
    </jasperReport>

Json数据:

[{"sectionType":"A","ClientAndBenificiary":"全国共済水産業協同組合連合会","DepartmentNameOfLender":"財務運用部 御中","TrustNoJapanese":"6018","ContractSignDate":"2013-04-23","TrustNo":"6018","ReportStartDate":"2016-07-01","EndStartDate":"2016-07-31","ReportPeriod":"2016-07-01から2016-07-31まで","Currency":"円","ShowLoanValue":"0","ShowCleanPrice":"0","ShowAccruedInt":"0","ShowDirtyPrice":"0","UDF1":"0.08","UDF2":"","ReportFrequency":"","QtrReportStartDate":"2016-07-01","QtrReportEndDate":"2016-08-01","Securities_No_Mon1_3":"JGB #289(10)Total","Lending_Fee_Mon1_3":"523645.000000000","Trust_Fee_Mon1_3":"174537.000000000","Consumption_Tax_Mon1_3":"13950.000000000","Trust_Fee_Tax_Included_Mon1_3":"188487.000000000","ReportLanguage":"ja","SectionType":"A"},{"sectionType":"A","ClientAndBenificiary":"全国共済水産業協同組合連合会","DepartmentNameOfLender":"財務運用部 御中","TrustNoJapanese":"6018","ContractSignDate":"2013-04-23","TrustNo":"6018","ReportStartDate":"2016-07-01","EndStartDate":"2016-07-31","ReportPeriod":"2016-07-01から2016-07-31まで","Currency":"円","ShowLoanValue":"0","ShowCleanPrice":"0","ShowAccruedInt":"0","ShowDirtyPrice":"0","UDF1":"0.08","UDF2":"","ReportFrequency":"","QtrReportStartDate":"2016-07-01","QtrReportEndDate":"2016-08-01","Securities_No_Mon1_3":"JGB #300(10)Total","Lending_Fee_Mon1_3":"268618.000000000","Trust_Fee_Mon1_3":"89529.000000000","Consumption_Tax_Mon1_3":"7148.000000000","Trust_Fee_Tax_Included_Mon1_3":"96677.000000000","ReportLanguage":"ja","SectionType":"A"},{"sectionType":"A","ClientAndBenificiary":"全国共済水産業協同組合連合会","DepartmentNameOfLender":"財務運用部 御中","TrustNoJapanese":"6018","ContractSignDate":"2013-04-23","TrustNo":"6018","ReportStartDate":"2016-07-01","EndStartDate":"2016-07-31","ReportPeriod":"2016-07-01から2016-07-31まで","Currency":"円","ShowLoanValue":"0","ShowCleanPrice":"0","ShowAccruedInt":"0","ShowDirtyPrice":"0","UDF1":"0.08","UDF2":"","ReportFrequency":"","QtrReportStartDate":"2016-07-01","QtrReportEndDate":"2016-08-01","Securities_No_Mon1_3":"JGB #305(10)Total","Lending_Fee_Mon1_3":"538950.000000000","Trust_Fee_Mon1_3":"179641.000000000","Consumption_Tax_Mon1_3":"14354.000000000","Trust_Fee_Tax_Included_Mon1_3":"193995.000000000","ReportLanguage":"ja","SectionType":"A"}]

我已经添加了我试图加载的JRXML和Json。当我在数据集中传递dataSourceExpression时,我只得到2行,但在源数据中有3行。请帮我解决这个问题

共有1个答案

甄志
2023-03-14

为了在 Jasper 中的表组件中显示数据,我们需要在主报告数据集之外设置新的数据集。我们可以在主报告数据集中编写任何虚拟查询,例如“从双数据库中选择 1”;

 类似资料:
  • 我有一个要转换成CSV格式的XML。我使用Jasper Reports来转换它,并使用Jasper Studio来设计JRXML。 这是XML: 我希望CSV格式包含以下列: fields_exitence分为3个(nonMap、ux和两者),属性在

  • 你好,在我解释我的问题之前,我会告诉你我想回答什么。 我正在尝试创建一个子报告,显示用户的不同收入。一个用户可以收到多次捐赠,出售了多栋房子/房产,赢得了比赛等。所有这些操作都有更多关于他们收到多少钱、缴纳的税款的详细信息,… 现在,我正在尝试在一个细节中显示用户的详细信息(姓名,姓氏,..;)。这行得通。下一个细节带将用于捐赠。我创建了一个子报表,在其中指定了此部分的布局。但是,此子报表所需的数

  • 我有一个要求,我必须阅读CSV文件并在Jasper中准备一份报告。我能够在常规文本字段中使用CSV数据源。但是当我在详细信息或摘要部分添加一个表时,它需要创建一个新的数据集。我成功地创建了它,但是当报告运行时,它无法从CSV数据源获取数据,我得到了一个空白的报告。如果我使用数据库而不是CSV,同样的事情也会发生。Jasper中有bug吗?

  • 嗯,我有一个主报告和一个子报告,在主报告中我有两个细节带。在第一个细节区,我放置了“主数据源”(来自fillReport),在第二个细节区,我放置了子报告(来自param的数据源)。 解决方案 经过大量的研究,我发现我对“主报告”和“子报告”的概念是错误的。当我们有一个“主报表”(与主数据源相关联)时,正确的做法是所有“子报表”都直接与此相关联。因此,我创建了3个子报告,并像“param”一样传递

  • 现在这个‘?’值将来自报表参数,例如CountryName。这可以使用参数化查询来完成,不是问题。现在我需要这个参数countryName来从另一个查询中获取数据,如下所示 简而言之,我希望将报表参数countryName的值绑定到上述查询的输出,并且我希望将此查询放入report it中。使用birt非常容易,但我想知道Jasper是否可能? 我是贾斯珀报告的新手。 我试图给出一个小场景来代表我

  • 当我从SourceForge网站下载JasperReports项目时,我创建JavaFx项目,我需要使用JasperReports库创建发票设计。提取的文件夹不包含dist文件夹,该文件夹包含构建发票设计所需的jar文件。文件夹包含这个文件夹,这里有什么问题“我是JasperReports的新手”