jasper-reports - iReport 4.1.3 表格组件从不显示数据集的第一个条目

标签 jasper-reports ireport xmltable

使用 ireport 表组件时,我遇到一个可能很简单的问题。我使用 XML 作为报告的数据源。

问题是该表从不显示与其关联的数据集的第一个条目。 想象一下我有这些数据:

<name>
   <first>adam 1</first>
   <last>sand 1</last>          
</name> 
<name>
   <first>adam 2</first>
   <last>sand 2</last>          
</name> 
<name>
   <first>adam 3</first>
   <last>sand 3</last>          
</name> 

输出(表)将为(除第一行之外的所有数据):

第一个最后一个
亚当2沙2
亚当3沙3

报告模板:

<?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="consumption_in_zones_data" pageWidth="500" pageHeight="802" columnWidth="500" 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"/>
    <property name="ireport.layers" value="##Tue Dec 06 12:01:43 GMT 2011\nlayer.0.name=Background\nlayer.0.visible=true\nlayer.0.id=0"/>
    <style name="table">
        <box>
            <pen lineWidth="1.0" lineColor="#000000"/>
        </box>
    </style>
    <style name="table_TH" mode="Opaque" backcolor="#F0F8FF">
        <box>
            <pen lineWidth="0.5" lineColor="#000000"/>
        </box>
    </style>
    <style name="table_CH" mode="Opaque" backcolor="#999999">
        <box>
            <pen lineWidth="0.5" lineColor="#000000"/>
        </box>
    </style>
    <style name="table_TD" mode="Opaque" backcolor="#FFFFCC">
        <box>
            <pen lineWidth="0.5" lineColor="#000000"/>
        </box>
    </style>
    <style name="table 1">
        <box>
            <pen lineWidth="1.0" lineColor="#000000"/>
        </box>
    </style>
    <style name="table 1_TH" mode="Opaque" backcolor="#F0F8FF">
        <box>
            <pen lineWidth="0.5" lineColor="#000000"/>
        </box>
    </style>
    <style name="table 1_CH" mode="Opaque" backcolor="#BFE1FF">
        <box>
            <pen lineWidth="0.5" lineColor="#000000"/>
        </box>
    </style>
    <style name="table 1_TD" mode="Opaque" backcolor="#FFFFFF">
        <box>
            <pen lineWidth="0.5" lineColor="#000000"/>
        </box>
    </style>
    <subDataset name="table dataset">
        <parameter name="ZoneID" class="java.lang.String"/>
        <parameter name="PERIOD" class="java.lang.String"/>
        <parameter name="UNIT" class="java.lang.String"/>
        <queryString language="xPath">
            <![CDATA[/OrganizationData/Building/Zone/Indicator/ActiveEnergy[ZoneID='$P{ZoneID}']]]>
        </queryString>
        <field name="time" class="java.lang.String">
            <fieldDescription><![CDATA[time]]></fieldDescription>
        </field>
        <field name="consumption" class="java.lang.Double">
            <fieldDescription><![CDATA[consumption]]></fieldDescription>
        </field>
    </subDataset>
    <parameter name="ZoneID" class="java.lang.String"/>
    <parameter name="PERIOD" class="java.lang.String"/>
    <parameter name="UNIT" class="java.lang.String"/>
    <queryString language="xPath">
        <![CDATA[/OrganizationData/Building/Zone/Indicator/ActiveEnergy[ZoneID='$P{ZoneID}']]]>
    </queryString>
    <field name="time" class="java.lang.String">
        <fieldDescription><![CDATA[time]]></fieldDescription>
    </field>
    <field name="consumption" class="java.lang.Double">
        <fieldDescription><![CDATA[consumption]]></fieldDescription>
    </field>
    <variable name="consumption_1" class="java.lang.Double" resetType="Column" calculation="Sum">
        <variableExpression><![CDATA[$F{consumption}]]></variableExpression>
    </variable>
    <variable name="consumption_2" class="java.lang.Double" resetType="Column" calculation="Sum">
        <variableExpression><![CDATA[$F{consumption}]]></variableExpression>
    </variable>
    <background>
        <band splitType="Stretch"/>
    </background>
    <detail>
        <band height="197" splitType="Stretch">
            <componentElement>
                <reportElement key="table 1" style="table 1" x="0" y="0" width="500" height="197"/>
                <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="table dataset">
                        <datasetParameter name="ZoneID">
                            <datasetParameterExpression><![CDATA[$P{ZoneID}]]></datasetParameterExpression>
                        </datasetParameter>
                        <datasetParameter name="PERIOD">
                            <datasetParameterExpression><![CDATA[$P{PERIOD}]]></datasetParameterExpression>
                        </datasetParameter>
                        <datasetParameter name="UNIT">
                            <datasetParameterExpression><![CDATA[$P{UNIT}]]></datasetParameterExpression>
                        </datasetParameter>
                        <dataSourceExpression><![CDATA[$P{REPORT_DATA_SOURCE}]]></dataSourceExpression>
                    </datasetRun>
                    <jr:column width="90">
                        <jr:tableHeader style="table 1_TH" height="30" rowSpan="1">
                            <textField>
                                <reportElement x="0" y="0" width="90" height="30"/>
                                <textElement textAlignment="Center"/>
                                <textFieldExpression><![CDATA[$P{PERIOD}]]></textFieldExpression>
                            </textField>
                        </jr:tableHeader>
                        <jr:detailCell style="table 1_TD" height="20" rowSpan="1">
                            <textField>
                                <reportElement x="0" y="0" width="90" height="20"/>
                                <textElement textAlignment="Center"/>
                                <textFieldExpression><![CDATA[$F{time}]]></textFieldExpression>
                            </textField>
                        </jr:detailCell>
                    </jr:column>
                    <jr:column width="90">
                        <jr:tableHeader style="table 1_TH" height="30" rowSpan="1">
                            <textField>
                                <reportElement x="0" y="0" width="90" height="30"/>
                                <textElement textAlignment="Center"/>
                                <textFieldExpression><![CDATA[$P{UNIT}]]></textFieldExpression>
                            </textField>
                        </jr:tableHeader>
                        <jr:detailCell style="table 1_TD" height="20" rowSpan="1">
                            <textField>
                                <reportElement x="0" y="0" width="90" height="20"/>
                                <textElement textAlignment="Center"/>
                                <textFieldExpression><![CDATA[$F{consumption}]]></textFieldExpression>
                            </textField>
                        </jr:detailCell>
                    </jr:column>
                </jr:table>
            </componentElement>
        </band>
    </detail>
</jasperReport>

数据片段:

<OrganizationData>
  <Building>
    <BuildingID>71721890-efd1-012c-c545-0a48cbee2b22</BuildingID>
    <BuildingName>PT</BuildingName>
    <Tariff>low</Tariff>
    <Zone>
      <ZoneID>bceba570-d0e2-012e-d950-7ac0bc5389eb</ZoneID>
      <BuildingID>71721890-efd1-012c-c545-0a48cbee2b22</BuildingID>
      <ZoneName>PT - Zone A</ZoneName>
      <Type>ROUT</Type>
      <Indicator>
        <IndicatorID>96a41e20-60d8-012d-516c-5aacf9dbb012</IndicatorID>
        <ZoneID>bceba570-d0e2-012e-d950-7ac0bc5389eb</ZoneID>
        <BuildingID>71721890-efd1-012c-c545-0a48cbee2b22</BuildingID>
        <IndicatorName>EA+ BlA P0</IndicatorName>
        <ActiveEnergy>
          <IndicatorID>96a41e20-60d8-012d-516c-5aacf9dbb012</IndicatorID>
          <ZoneID>bceba570-d0e2-012e-d950-7ac0bc5389eb</ZoneID>
          <BuildingID>71721890-efd1-012c-c545-0a48cbee2b22</BuildingID>
          <time>01 Oct</time>
          <consumption>0.1</consumption>
        </ActiveEnergy>
        <ActiveEnergy>
          <IndicatorID>96a41e20-60d8-012d-516c-5aacf9dbb012</IndicatorID>
          <ZoneID>bceba570-d0e2-012e-d950-7ac0bc5389eb</ZoneID>
          <BuildingID>71721890-efd1-012c-c545-0a48cbee2b22</BuildingID>
          <time>02 Oct</time>
          <consumption>0.1</consumption>
        </ActiveEnergy>
      </Indicator>
    </Zone>
  </Building>
</OrganizationData>

提前致谢, 努诺

最佳答案

我刚刚使用此测试用例检查了 table 元素。

我的模板:

<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="tablesample2" language="groovy" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20">
    <style name="table">
        <box>
            <pen lineWidth="1.0" lineColor="#000000"/>
        </box>
    </style>
    <style name="table_TH" mode="Opaque" backcolor="#F0F8FF">
        <box>
            <pen lineWidth="0.5" lineColor="#000000"/>
        </box>
    </style>
    <style name="table_CH" mode="Opaque" backcolor="#BFE1FF">
        <box>
            <pen lineWidth="0.5" lineColor="#000000"/>
        </box>
    </style>
    <style name="table_TD" mode="Opaque" backcolor="#FFFFFF">
        <box>
            <pen lineWidth="0.5" lineColor="#000000"/>
        </box>
    </style>
    <subDataset name="Table Dataset 1">
        <field name="city" class="java.lang.String"/>
        <field name="id" class="java.lang.String"/>
    </subDataset>
    <queryString>
        <![CDATA[]]>
    </queryString>
    <field name="city" class="java.lang.String"/>
    <field name="id" class="java.lang.String"/>
    <detail>
        <band height="80" splitType="Stretch">
            <componentElement>
                <reportElement key="table" style="table" x="100" y="0" width="270" height="80"/>
                <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="Table Dataset 1">
                        <dataSourceExpression><![CDATA[$P{REPORT_DATA_SOURCE}]]></dataSourceExpression>
                    </datasetRun>
                    <jr:column width="90">
                        <jr:detailCell style="table_TD" height="20" rowSpan="1">
                            <textField>
                                <reportElement x="0" y="0" width="90" height="20"/>
                                <textElement/>
                                <textFieldExpression><![CDATA[$F{city}]]></textFieldExpression>
                            </textField>
                        </jr:detailCell>
                    </jr:column>
                    <jr:column width="90">
                        <jr:detailCell style="table_TD" height="20" rowSpan="1">
                            <textField>
                                <reportElement x="0" y="0" width="90" height="20"/>
                                <textElement/>
                                <textFieldExpression><![CDATA[$F{id}]]></textFieldExpression>
                            </textField>
                        </jr:detailCell>
                    </jr:column>
                    <jr:column width="90">
                        <jr:detailCell style="table_TD" height="20" rowSpan="1"/>
                    </jr:column>
                </jr:table>
            </componentElement>
        </band>
    </detail>
</jasperReport>

我的 csv 数据文件是:

"Dallas",47,"Janet Fuller","445 Upland Pl.","Trial"
"Lyon",38,"Andrew Heiniger","347 College Av.","Active"
"Dallas",43,"Susanne Smith","2 Upland Pl.","Active"
"Berne",22,"Bill Ott","250 - 20th Ave.","Active"
"Boston",32,"Michael Ott","339 College Av.","Trial"
"Dallas",4,"Sylvia Ringer","365 College Av.","Active"
"Boston",23,"Julia Heiniger","358 College Av.","Active"
"Chicago",39,"Mary Karsen","202 College Av.","Active"
"Dallas",40,"Susanne Miller","440 - 20th Ave.","Trial"
"Berne",9,"James Schneider","277 Seventh Av.","Active"
"Dallas",36,"John Steel","276 Upland Pl.","Suspended"
"Chicago",35,"George Karsen","412 College Av.","Suspended"
"Dallas",37,"Michael Clancy","19 Seventh Av.","Deleted"
"Lyon",2,"Anne Miller","20 Upland Pl.","Active"
"Dallas",0,"Laura Steel","429 Seventh Av.","Active"
"Lyon",28,"Susanne White","74 - 20th Ave.","Deleted"
"Paris",5,"Laura Miller","294 Seventh Av.","Active"
"Lyon",17,"Laura Ott","443 Seventh Av.","Active"
"New York",46,"Andrew May","172 Seventh Av.","Active"
"New York",44,"Sylvia Ott","361 College Av.","Active"
"Dallas",19,"Susanne Heiniger","86 - 20th Ave.","Active"
"Chicago",11,"Julia White","412 Upland Pl.","Active"
"Dallas",10,"Anne Fuller","135 Upland Pl.","Active"
"New York",41,"Bill King","546 College Av.","Deleted"
"Oslo",45,"Janet May","396 Seventh Av.","Active"
"Paris",18,"Sylvia Fuller","158 - 20th Ave.","Trial"
"San Francisco",48,"Robert White","549 Seventh Av.","Active"
"Paris",25,"Sylvia Steel","269 College Av.","Suspended"
"San Francisco",7,"James Peterson","231 Upland Pl.","Active"
"Oslo",42,"Robert Ott","503 Seventh Av.","Trial"

表格中缺少数据源的第一行。

我认为这是与主数据源迭代相关的问题。您可以阅读
Why is the first record missing from my subreport?
community.jaspersoft.com 上发帖。

关于jasper-reports - iReport 4.1.3 表格组件从不显示数据集的第一个条目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8414953/

相关文章:

jasper-reports - 每个子报表一个 excel 表(主报表中没有组)jaspersoft iReport

jasper-reports - iReports ORA-00911 : invalid character

xml - 如何在 Oracle 中对以下 XML 使用 XMLTable

xslt - 在 FOP 中用长字包裹在表格单元格中

java - 如何使用 DynamicJasper API 在 pdf 报告的页脚中显示图像?

java - jasperreports - pdf 字体粗体仅显示普通字体

java - bigdecimal 作为参数

xml - 从复杂的 Oracle XMLTYPE 数据中进行选择和插入

java - 移动平台上的 JasperReports

jasper-reports - Jaspersoft Studio 在为报告更改数据适配器时添加 uuid