【问题标题】:iReport 4.1.3 table component never shows the first entry of the datasetiReport 4.1.3 表格组件从不显示数据集的第一个条目
【发布时间】:2017-07-22 01:36:18
【问题描述】:

在使用 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>

数据sn-p:

<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>

提前致谢, 努诺

【问题讨论】:

标签: jasper-reports ireport xmltable


【解决方案1】:

我刚刚用这个测试用例检查了 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"

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

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

【讨论】:

  • 首先感谢您的回复。我无法从查询中删除 ZoneID,因为此报告实际上是一个子报告,它接收 ZoneID 以过滤与其关联的能量。如果我删除它,表格会显示该建筑物所有区域的所有能量(奇怪的是没有再次显示第一行)。谢谢
  • 您能发布包含更多我的信息的数据文件吗?我再试一次
  • 我只有ZoneID 的数据等于参数。这是错的吗?这是我数据文件中的前三个ActiveEnergy
  • 是的,它适合您。你在使用表格组件吗?如果我只是将字段放在详细信息带中,它会为正确的 ZoneID 打印所有字段。我的问题是使用表格组件。
  • 是的,我已将您的 jrxml 文件与我的数据文件一起使用
猜你喜欢
  • 2020-08-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-12-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-04-19
相关资源
最近更新 更多