删除嵌套列表中的空行的问题 (JasperReports)
Problems with removing empty lines in nested lists (JasperReports)
我想创建一个报告,列出来自 xml 数据源的订单项目数据。对于每个项目,我想显示项目的名称、类型和 ID。订单项具有树结构,这意味着存在根项,并且某些根项可能具有 children(并且 child 项可能具有 children,等等)。因为订单项具有树状结构,所以我选择在报表中使用列表和嵌套列表来创建此报表,以保持树状结构。换句话说,如果一个项目可能有一个 child,我已经在 [parent] 项目的列表范围内为该 child 创建了一个嵌套列表。如果根据数据集中的查询没有找到给定列表的行,则应删除列表行。我遇到的问题是,当嵌套列表没有行时,有时会显示白色 space。
这里是例子XML数据:
<xml>
<order>
<items>
<itemId>1</itemId>
<itemType>G</itemType>
<name>G1</name>
<children>
<childType>typeSV</childType>
<items>
<itemId>2</itemId>
<name>SV1</name>
<children>
<childType>typeCWI</childType>
</children>
</items>
</children>
<children>
<childType>typeIAR</childType>
<items>
<itemId>3</itemId>
<name>IAR1</name>
</items>
</children>
</items>
<items>
<itemId>4</itemId>
<itemType>G</itemType>
<name>G2</name>
<children>
<childType>typeSV</childType>
<items>
<itemId>5</itemId>
<name>SV2</name>
<children>
<childType>typeCWI</childType>
<items>
<itemId>6</itemId>
<name>CWI</name>
<children>
<childType>typeUWSAT</childType>
<items>
<itemId>7</itemId>
<name>UWSAT</name>
</items>
</children>
</items>
</children>
</items>
</children>
</items>
<items>
<itemId>8</itemId>
<itemType>G</itemType>
<name>G3</name>
<children>
<childType>typeSV</childType>
<items>
<itemId>9</itemId>
<name>SV3</name>
<children>
<childType>typeCWI</childType>
</children>
</items>
</children>
</items>
<items>
<itemId>10</itemId>
<itemType>G</itemType>
<name>G4</name>
<children>
<childType>typeSV</childType>
</children>
</items>
<items>
<itemId>11</itemId>
<itemType>AD</itemType>
<name>AD1</name>
<children>
<childType>typeCP</childType>
<items>
<itemId>12</itemId>
<name>CP1</name>
<children>
<childType>typeAC</childType>
</children>
</items>
</children>
</items>
</order></xml>
JRXML:
<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="TestXml" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" isIgnorePagination="true" uuid="29a85d17-1c73-426a-a943-abd1a79d4d69">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="TextXml"/>
<subDataset name="OrderItems" uuid="afd926ee-2c1e-4872-94e5-c3827d6ee20e">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="TextXml"/>
<queryString language="xPath">
<![CDATA[//items]]>
</queryString>
<field name="itemId" class="java.lang.String">
<fieldDescription>
<![CDATA[itemId]]>
</fieldDescription>
</field>
<field name="name" class="java.lang.String">
<fieldDescription>
<![CDATA[name]]>
</fieldDescription>
</field>
<field name="itemType" class="java.lang.String">
<fieldDescription>
<![CDATA[itemType]]>
</fieldDescription>
</field>
<field name="childType" class="java.lang.String">
<fieldDescription>
<![CDATA[../childType]]>
</fieldDescription>
</field>
</subDataset>
<queryString language="xPath">
<![CDATA[/xml]]>
</queryString>
<background>
<band splitType="Stretch"/>
</background>
<detail>
<band height="120" splitType="Stretch">
<property name="com.jaspersoft.studio.unit.height" value="pixel"/>
<frame>
<reportElement stretchType="ContainerBottom" x="0" y="0" width="560" height="120" isRemoveLineWhenBlank="true" uuid="cd28978a-d108-4dbf-bbdd-e4246bfb3034"/>
<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>
<componentElement>
<reportElement positionType="Float" stretchType="ContainerBottom" x="0" y="0" width="560" height="120" isRemoveLineWhenBlank="true" uuid="56683f9b-46b2-432c-bc9d-325c6c4aceed">
<property name="net.sf.jasperreports.export.headertoolbar.table.name" value="G"/>
</reportElement>
<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="OrderItems" uuid="5ad748aa-acb5-47eb-96e2-d62692015afc">
<dataSourceExpression>
<![CDATA[((net.sf.jasperreports.engine.data.JRXmlDataSource)$P{REPORT_DATA_SOURCE}).dataSource("/xml/order/items[itemType='G']")]]>
</dataSourceExpression>
</datasetRun>
<jr:listContents height="120" width="560">
<frame>
<reportElement positionType="Float" stretchType="ContainerBottom" x="0" y="0" width="560" height="30" isRemoveLineWhenBlank="true" uuid="98750caa-ff8c-40da-bddd-57ef7d2db52f"/>
<box>
<topPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<leftPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
<bottomPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<rightPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
</box>
<textField>
<reportElement positionType="Float" stretchType="ContainerBottom" mode="Opaque" x="360" y="0" width="100" height="30" backcolor="#A1A1A1" uuid="d58577b5-f861-496a-877e-c2a288b79d18"/>
<box>
<topPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
<leftPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<bottomPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
<rightPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
</box>
<textElement textAlignment="Left"/>
<textFieldExpression>
<![CDATA[$F{itemType}]]>
</textFieldExpression>
</textField>
<textField>
<reportElement positionType="Float" stretchType="ContainerBottom" mode="Opaque" x="460" y="0" width="100" height="30" backcolor="#A1A1A1" uuid="672a536b-199a-4ee3-a363-30e3b255d7f6"/>
<box>
<topPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
<leftPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<bottomPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
<rightPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
</box>
<textElement textAlignment="Left"/>
<textFieldExpression>
<![CDATA[$F{itemId}]]>
</textFieldExpression>
</textField>
<textField>
<reportElement positionType="Float" stretchType="ContainerBottom" mode="Opaque" x="0" y="0" width="359" height="30" backcolor="#A1A1A1" uuid="1670ab91-d0bb-43a1-9898-d8bb9cdaaec8"/>
<box>
<leftPen lineWidth="1.0"/>
</box>
<textElement textAlignment="Left"/>
<textFieldExpression>
<![CDATA[$F{name}]]>
</textFieldExpression>
</textField>
</frame>
<frame>
<reportElement positionType="Float" stretchType="ContainerBottom" x="0" y="30" width="560" height="90" isRemoveLineWhenBlank="true" uuid="b658a693-c1f5-45d8-8cd7-73bc8e77c76e">
<property name="com.jaspersoft.studio.unit.height" value="pixel"/>
</reportElement>
<frame>
<reportElement positionType="Float" stretchType="ContainerBottom" x="0" y="0" width="560" height="30" isRemoveLineWhenBlank="true" uuid="1f113e02-72f0-4b03-86e1-71a7341837fa"/>
<box>
<topPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
<leftPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
<bottomPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
<rightPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
</box>
<componentElement>
<reportElement positionType="Float" stretchType="ContainerBottom" x="0" y="0" width="560" height="30" isRemoveLineWhenBlank="true" uuid="67539ab7-8fbe-45ce-9cbf-4f966415a2ef">
<property name="net.sf.jasperreports.export.headertoolbar.table.name" value="IAR"/>
</reportElement>
<jr:list printOrder="Vertical">
<datasetRun subDataset="OrderItems" uuid="1a39b86b-eb8b-4fea-a2f4-d8278390b099">
<dataSourceExpression>
<![CDATA[((net.sf.jasperreports.engine.data.JRXmlDataSource)$P{REPORT_DATA_SOURCE}).dataSource("/xml/order/items[itemId='"+$F{itemId}+"']/children[childType='typeIAR']/items")]]>
</dataSourceExpression>
</datasetRun>
<jr:listContents height="30" width="560">
<frame>
<reportElement positionType="Float" x="0" y="0" width="560" height="30" isRemoveLineWhenBlank="true" uuid="bc9e2c9e-bca3-46ba-87aa-5bceb222bda0"/>
<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="0.0" lineStyle="Solid" lineColor="#000000"/>
</box>
<textField>
<reportElement positionType="Float" stretchType="ContainerBottom" x="460" y="0" width="100" height="30" uuid="e31e95dc-714f-4f89-85b0-cb2927d3c0a4">
<property name="com.jaspersoft.studio.unit.x" value="pixel"/>
</reportElement>
<box>
<topPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
<leftPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<bottomPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
<rightPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
</box>
<textFieldExpression>
<![CDATA[$F{itemId}]]>
</textFieldExpression>
</textField>
<textField>
<reportElement positionType="Float" stretchType="ContainerBottom" x="30" y="0" width="330" height="30" uuid="526c14ee-a12e-4156-b130-a7d667136fc2">
<property name="com.jaspersoft.studio.unit.x" value="pixel"/>
</reportElement>
<box>
<topPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
<leftPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<bottomPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
<rightPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
</box>
<textFieldExpression>
<![CDATA[$F{name}]]>
</textFieldExpression>
</textField>
<textField>
<reportElement positionType="Float" stretchType="ContainerBottom" x="360" y="0" width="100" height="30" uuid="33e53141-5aca-4ec5-af78-edf1c930d7c4">
<property name="com.jaspersoft.studio.unit.x" value="pixel"/>
</reportElement>
<box>
<topPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
<leftPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<bottomPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
<rightPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
</box>
<textFieldExpression>
<![CDATA[$F{childType}]]>
</textFieldExpression>
</textField>
</frame>
</jr:listContents>
</jr:list>
</componentElement>
</frame>
<frame>
<reportElement positionType="Float" stretchType="ContainerBottom" x="0" y="30" width="560" height="60" isRemoveLineWhenBlank="true" uuid="38ba008a-05ee-4c35-9d36-c0b3e8fc36ea">
<property name="com.jaspersoft.studio.unit.y" value="pixel"/>
<property name="com.jaspersoft.studio.unit.height" value="pixel"/>
<property name="com.jaspersoft.studio.unit.x" value="pixel"/>
</reportElement>
<componentElement>
<reportElement positionType="Float" stretchType="ContainerBottom" x="0" y="0" width="560" height="60" isRemoveLineWhenBlank="true" uuid="613fc942-f6b3-449b-836d-58d469bbbc53">
<property name="com.jaspersoft.studio.unit.x" value="pixel"/>
<property name="net.sf.jasperreports.export.headertoolbar.table.name" value="SV"/>
<property name="com.jaspersoft.studio.unit.height" value="pixel"/>
</reportElement>
<jr:list printOrder="Vertical">
<datasetRun subDataset="OrderItems" uuid="992b798d-0ad5-4c5b-b245-1a40d055b7f5">
<dataSourceExpression>
<![CDATA[((net.sf.jasperreports.engine.data.JRXmlDataSource)$P{REPORT_DATA_SOURCE}).dataSource("/xml/order/items[itemId='"+$F{itemId}+"']/children[childType='typeSV']/items")]]>
</dataSourceExpression>
</datasetRun>
<jr:listContents height="60" width="560">
<frame>
<reportElement positionType="Float" x="0" y="0" width="560" height="30" isRemoveLineWhenBlank="true" uuid="f063936c-ab95-465d-9501-0ed8e5d4dacc"/>
<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="0.0" lineStyle="Solid" lineColor="#000000"/>
</box>
<textField>
<reportElement positionType="Float" x="460" y="0" width="100" height="30" uuid="4c7e80d3-6bc4-4281-8c7f-2ba6ba18fa74">
<property name="com.jaspersoft.studio.unit.width" value="pixel"/>
<property name="com.jaspersoft.studio.unit.x" value="pixel"/>
<property name="com.jaspersoft.studio.unit.y" value="pixel"/>
</reportElement>
<box>
<topPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
<leftPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<bottomPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
<rightPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
</box>
<textFieldExpression>
<![CDATA[$F{itemId}]]>
</textFieldExpression>
</textField>
<textField>
<reportElement positionType="Float" x="30" y="0" width="330" height="30" uuid="96042aa9-402a-4a8f-b008-b3d0ff94becd">
<property name="com.jaspersoft.studio.unit.x" value="pixel"/>
</reportElement>
<box>
<topPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
<leftPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<bottomPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
<rightPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
</box>
<textFieldExpression>
<![CDATA[$F{name}]]>
</textFieldExpression>
</textField>
<textField>
<reportElement positionType="Float" x="360" y="0" width="100" height="30" uuid="2d3b1a7b-4bfb-4c12-bdaa-741af76a52fd">
<property name="com.jaspersoft.studio.unit.width" value="pixel"/>
<property name="com.jaspersoft.studio.unit.x" value="pixel"/>
<property name="com.jaspersoft.studio.unit.y" value="pixel"/>
</reportElement>
<box>
<topPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
<leftPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<bottomPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
<rightPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
</box>
<textFieldExpression>
<![CDATA[$F{childType}]]>
</textFieldExpression>
</textField>
</frame>
<frame>
<reportElement positionType="Float" stretchType="ContainerBottom" x="0" y="30" width="560" height="30" isRemoveLineWhenBlank="true" uuid="77c3cf69-01ec-41c0-86e0-9b81d17c6a75">
<property name="com.jaspersoft.studio.unit.y" value="pixel"/>
<property name="com.jaspersoft.studio.unit.x" value="pixel"/>
<property name="com.jaspersoft.studio.unit.height" value="pixel"/>
</reportElement>
<componentElement>
<reportElement key="" positionType="Float" stretchType="ContainerBottom" x="0" y="0" width="560" height="30" isRemoveLineWhenBlank="true" uuid="4bec04d5-cd1f-4236-8867-aeba9579161a">
<property name="com.jaspersoft.studio.unit.y" value="pixel"/>
<property name="com.jaspersoft.studio.unit.x" value="pixel"/>
<property name="net.sf.jasperreports.export.headertoolbar.table.name" value="CWI"/>
</reportElement>
<jr:list printOrder="Vertical">
<datasetRun subDataset="OrderItems" uuid="7517e1b5-fef5-4466-acdb-c83b082bbc1a">
<dataSourceExpression>
<![CDATA[((net.sf.jasperreports.engine.data.JRXmlDataSource)$P{REPORT_DATA_SOURCE}).dataSource("/xml/order/items/children/items[itemId='"+$F{itemId}+"']/children[childType='typeCWI']/items")]]>
</dataSourceExpression>
</datasetRun>
<jr:listContents height="30" width="560">
<frame>
<reportElement positionType="Float" stretchType="ContainerBottom" x="0" y="0" width="560" height="30" isRemoveLineWhenBlank="true" uuid="9fcf1658-09b4-4d40-983b-7934d6c44e43"/>
<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="0.0" lineStyle="Solid" lineColor="#000000"/>
</box>
<textField>
<reportElement positionType="Float" x="460" y="0" width="100" height="30" uuid="c51d6125-185c-4733-bcf2-a9828229b091">
<property name="com.jaspersoft.studio.unit.width" value="pixel"/>
<property name="com.jaspersoft.studio.unit.x" value="pixel"/>
<property name="com.jaspersoft.studio.unit.y" value="pixel"/>
</reportElement>
<box>
<topPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
<leftPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<bottomPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
<rightPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
</box>
<textFieldExpression>
<![CDATA[$F{itemId}]]>
</textFieldExpression>
</textField>
<textField>
<reportElement positionType="Float" x="60" y="0" width="300" height="30" uuid="5f06b7e6-7d49-4dee-832f-a5a35285a5a6">
<property name="com.jaspersoft.studio.unit.y" value="pixel"/>
<property name="com.jaspersoft.studio.unit.x" value="pixel"/>
</reportElement>
<box>
<topPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
<leftPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<bottomPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
<rightPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
</box>
<textFieldExpression>
<![CDATA[$F{name}]]>
</textFieldExpression>
</textField>
<textField>
<reportElement positionType="Float" x="360" y="0" width="100" height="30" uuid="259ab20e-a5e5-4fa1-ad8a-4cc602e57ad0">
<property name="com.jaspersoft.studio.unit.width" value="pixel"/>
<property name="com.jaspersoft.studio.unit.y" value="pixel"/>
<property name="com.jaspersoft.studio.unit.x" value="pixel"/>
</reportElement>
<box>
<topPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
<leftPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<bottomPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
<rightPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
</box>
<textFieldExpression>
<![CDATA[$F{childType}]]>
</textFieldExpression>
</textField>
</frame>
</jr:listContents>
</jr:list>
</componentElement>
</frame>
</jr:listContents>
</jr:list>
</componentElement>
</frame>
</frame>
</jr:listContents>
</jr:list>
</componentElement>
</frame>
</band>
</detail>
下面我将此报告导出为 .xls 格式并截取了屏幕截图,以说明我现在遇到的实际结果和期望的结果。
XLS 格式的实际结果屏幕截图(红色线条环绕不需要的白色 space):
所需结果的 XLS 格式屏幕截图:
当 IAR 项目的嵌套列表没有行(使用 "Remove Line When Blank" 选项”)或既没有 IAR- 也没有 SV-type 各自嵌套列表的行。但是,当 SV-type 项的列表为 non-empty 且 CWI-type 项为空时,白色 space 显示 CWI-type行将被定位。我尝试通过浮动所有报告组件(例如文本字段、列表、框架等)来删除不需要的白色 space,将所有报告组件的拉伸类型设置为 "ElementGroupBottom" 和 "ContainerBottom",但无济于事。
有谁知道我应该如何制作这份报告才能达到预期的结果?
您可以将 List SV 元素的高度减小到 30,同时将其单元格高度保留为 60。这样,当 List CWI 中没有数据时,单元格高度将保持为 30,但会拉伸到当 List CWI 产生行数时为 60 或更多。
缺点是 List CWI 在 Jaspersoft Sudio 的设计视图中会被遮挡,您只能通过向下钻取到 List SV 才能看到它。
更改如下:
- 将 List SV 单元格高度保留为 60
- 将 List SV 元素高度从 60 更改为 30(请注意,在此步骤中,Studio 可能会自动将单元格高度更改为 30,如果这样做,则将其设置回 60)
- 将放置 List SV 的框架的高度从 60 更改为 30
- 将父框架的高度从 90 更改为 60
- 将列表 G 的元素和单元格高度从 120 更改为 90
- 将细节带和顶层框架的高度从 120 更改为 90
我想创建一个报告,列出来自 xml 数据源的订单项目数据。对于每个项目,我想显示项目的名称、类型和 ID。订单项具有树结构,这意味着存在根项,并且某些根项可能具有 children(并且 child 项可能具有 children,等等)。因为订单项具有树状结构,所以我选择在报表中使用列表和嵌套列表来创建此报表,以保持树状结构。换句话说,如果一个项目可能有一个 child,我已经在 [parent] 项目的列表范围内为该 child 创建了一个嵌套列表。如果根据数据集中的查询没有找到给定列表的行,则应删除列表行。我遇到的问题是,当嵌套列表没有行时,有时会显示白色 space。
这里是例子XML数据:
<xml>
<order>
<items>
<itemId>1</itemId>
<itemType>G</itemType>
<name>G1</name>
<children>
<childType>typeSV</childType>
<items>
<itemId>2</itemId>
<name>SV1</name>
<children>
<childType>typeCWI</childType>
</children>
</items>
</children>
<children>
<childType>typeIAR</childType>
<items>
<itemId>3</itemId>
<name>IAR1</name>
</items>
</children>
</items>
<items>
<itemId>4</itemId>
<itemType>G</itemType>
<name>G2</name>
<children>
<childType>typeSV</childType>
<items>
<itemId>5</itemId>
<name>SV2</name>
<children>
<childType>typeCWI</childType>
<items>
<itemId>6</itemId>
<name>CWI</name>
<children>
<childType>typeUWSAT</childType>
<items>
<itemId>7</itemId>
<name>UWSAT</name>
</items>
</children>
</items>
</children>
</items>
</children>
</items>
<items>
<itemId>8</itemId>
<itemType>G</itemType>
<name>G3</name>
<children>
<childType>typeSV</childType>
<items>
<itemId>9</itemId>
<name>SV3</name>
<children>
<childType>typeCWI</childType>
</children>
</items>
</children>
</items>
<items>
<itemId>10</itemId>
<itemType>G</itemType>
<name>G4</name>
<children>
<childType>typeSV</childType>
</children>
</items>
<items>
<itemId>11</itemId>
<itemType>AD</itemType>
<name>AD1</name>
<children>
<childType>typeCP</childType>
<items>
<itemId>12</itemId>
<name>CP1</name>
<children>
<childType>typeAC</childType>
</children>
</items>
</children>
</items>
</order></xml>
JRXML:
<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="TestXml" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" isIgnorePagination="true" uuid="29a85d17-1c73-426a-a943-abd1a79d4d69">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="TextXml"/>
<subDataset name="OrderItems" uuid="afd926ee-2c1e-4872-94e5-c3827d6ee20e">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="TextXml"/>
<queryString language="xPath">
<![CDATA[//items]]>
</queryString>
<field name="itemId" class="java.lang.String">
<fieldDescription>
<![CDATA[itemId]]>
</fieldDescription>
</field>
<field name="name" class="java.lang.String">
<fieldDescription>
<![CDATA[name]]>
</fieldDescription>
</field>
<field name="itemType" class="java.lang.String">
<fieldDescription>
<![CDATA[itemType]]>
</fieldDescription>
</field>
<field name="childType" class="java.lang.String">
<fieldDescription>
<![CDATA[../childType]]>
</fieldDescription>
</field>
</subDataset>
<queryString language="xPath">
<![CDATA[/xml]]>
</queryString>
<background>
<band splitType="Stretch"/>
</background>
<detail>
<band height="120" splitType="Stretch">
<property name="com.jaspersoft.studio.unit.height" value="pixel"/>
<frame>
<reportElement stretchType="ContainerBottom" x="0" y="0" width="560" height="120" isRemoveLineWhenBlank="true" uuid="cd28978a-d108-4dbf-bbdd-e4246bfb3034"/>
<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>
<componentElement>
<reportElement positionType="Float" stretchType="ContainerBottom" x="0" y="0" width="560" height="120" isRemoveLineWhenBlank="true" uuid="56683f9b-46b2-432c-bc9d-325c6c4aceed">
<property name="net.sf.jasperreports.export.headertoolbar.table.name" value="G"/>
</reportElement>
<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="OrderItems" uuid="5ad748aa-acb5-47eb-96e2-d62692015afc">
<dataSourceExpression>
<![CDATA[((net.sf.jasperreports.engine.data.JRXmlDataSource)$P{REPORT_DATA_SOURCE}).dataSource("/xml/order/items[itemType='G']")]]>
</dataSourceExpression>
</datasetRun>
<jr:listContents height="120" width="560">
<frame>
<reportElement positionType="Float" stretchType="ContainerBottom" x="0" y="0" width="560" height="30" isRemoveLineWhenBlank="true" uuid="98750caa-ff8c-40da-bddd-57ef7d2db52f"/>
<box>
<topPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<leftPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
<bottomPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<rightPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
</box>
<textField>
<reportElement positionType="Float" stretchType="ContainerBottom" mode="Opaque" x="360" y="0" width="100" height="30" backcolor="#A1A1A1" uuid="d58577b5-f861-496a-877e-c2a288b79d18"/>
<box>
<topPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
<leftPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<bottomPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
<rightPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
</box>
<textElement textAlignment="Left"/>
<textFieldExpression>
<![CDATA[$F{itemType}]]>
</textFieldExpression>
</textField>
<textField>
<reportElement positionType="Float" stretchType="ContainerBottom" mode="Opaque" x="460" y="0" width="100" height="30" backcolor="#A1A1A1" uuid="672a536b-199a-4ee3-a363-30e3b255d7f6"/>
<box>
<topPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
<leftPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<bottomPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
<rightPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
</box>
<textElement textAlignment="Left"/>
<textFieldExpression>
<![CDATA[$F{itemId}]]>
</textFieldExpression>
</textField>
<textField>
<reportElement positionType="Float" stretchType="ContainerBottom" mode="Opaque" x="0" y="0" width="359" height="30" backcolor="#A1A1A1" uuid="1670ab91-d0bb-43a1-9898-d8bb9cdaaec8"/>
<box>
<leftPen lineWidth="1.0"/>
</box>
<textElement textAlignment="Left"/>
<textFieldExpression>
<![CDATA[$F{name}]]>
</textFieldExpression>
</textField>
</frame>
<frame>
<reportElement positionType="Float" stretchType="ContainerBottom" x="0" y="30" width="560" height="90" isRemoveLineWhenBlank="true" uuid="b658a693-c1f5-45d8-8cd7-73bc8e77c76e">
<property name="com.jaspersoft.studio.unit.height" value="pixel"/>
</reportElement>
<frame>
<reportElement positionType="Float" stretchType="ContainerBottom" x="0" y="0" width="560" height="30" isRemoveLineWhenBlank="true" uuid="1f113e02-72f0-4b03-86e1-71a7341837fa"/>
<box>
<topPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
<leftPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
<bottomPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
<rightPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
</box>
<componentElement>
<reportElement positionType="Float" stretchType="ContainerBottom" x="0" y="0" width="560" height="30" isRemoveLineWhenBlank="true" uuid="67539ab7-8fbe-45ce-9cbf-4f966415a2ef">
<property name="net.sf.jasperreports.export.headertoolbar.table.name" value="IAR"/>
</reportElement>
<jr:list printOrder="Vertical">
<datasetRun subDataset="OrderItems" uuid="1a39b86b-eb8b-4fea-a2f4-d8278390b099">
<dataSourceExpression>
<![CDATA[((net.sf.jasperreports.engine.data.JRXmlDataSource)$P{REPORT_DATA_SOURCE}).dataSource("/xml/order/items[itemId='"+$F{itemId}+"']/children[childType='typeIAR']/items")]]>
</dataSourceExpression>
</datasetRun>
<jr:listContents height="30" width="560">
<frame>
<reportElement positionType="Float" x="0" y="0" width="560" height="30" isRemoveLineWhenBlank="true" uuid="bc9e2c9e-bca3-46ba-87aa-5bceb222bda0"/>
<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="0.0" lineStyle="Solid" lineColor="#000000"/>
</box>
<textField>
<reportElement positionType="Float" stretchType="ContainerBottom" x="460" y="0" width="100" height="30" uuid="e31e95dc-714f-4f89-85b0-cb2927d3c0a4">
<property name="com.jaspersoft.studio.unit.x" value="pixel"/>
</reportElement>
<box>
<topPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
<leftPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<bottomPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
<rightPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
</box>
<textFieldExpression>
<![CDATA[$F{itemId}]]>
</textFieldExpression>
</textField>
<textField>
<reportElement positionType="Float" stretchType="ContainerBottom" x="30" y="0" width="330" height="30" uuid="526c14ee-a12e-4156-b130-a7d667136fc2">
<property name="com.jaspersoft.studio.unit.x" value="pixel"/>
</reportElement>
<box>
<topPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
<leftPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<bottomPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
<rightPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
</box>
<textFieldExpression>
<![CDATA[$F{name}]]>
</textFieldExpression>
</textField>
<textField>
<reportElement positionType="Float" stretchType="ContainerBottom" x="360" y="0" width="100" height="30" uuid="33e53141-5aca-4ec5-af78-edf1c930d7c4">
<property name="com.jaspersoft.studio.unit.x" value="pixel"/>
</reportElement>
<box>
<topPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
<leftPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<bottomPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
<rightPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
</box>
<textFieldExpression>
<![CDATA[$F{childType}]]>
</textFieldExpression>
</textField>
</frame>
</jr:listContents>
</jr:list>
</componentElement>
</frame>
<frame>
<reportElement positionType="Float" stretchType="ContainerBottom" x="0" y="30" width="560" height="60" isRemoveLineWhenBlank="true" uuid="38ba008a-05ee-4c35-9d36-c0b3e8fc36ea">
<property name="com.jaspersoft.studio.unit.y" value="pixel"/>
<property name="com.jaspersoft.studio.unit.height" value="pixel"/>
<property name="com.jaspersoft.studio.unit.x" value="pixel"/>
</reportElement>
<componentElement>
<reportElement positionType="Float" stretchType="ContainerBottom" x="0" y="0" width="560" height="60" isRemoveLineWhenBlank="true" uuid="613fc942-f6b3-449b-836d-58d469bbbc53">
<property name="com.jaspersoft.studio.unit.x" value="pixel"/>
<property name="net.sf.jasperreports.export.headertoolbar.table.name" value="SV"/>
<property name="com.jaspersoft.studio.unit.height" value="pixel"/>
</reportElement>
<jr:list printOrder="Vertical">
<datasetRun subDataset="OrderItems" uuid="992b798d-0ad5-4c5b-b245-1a40d055b7f5">
<dataSourceExpression>
<![CDATA[((net.sf.jasperreports.engine.data.JRXmlDataSource)$P{REPORT_DATA_SOURCE}).dataSource("/xml/order/items[itemId='"+$F{itemId}+"']/children[childType='typeSV']/items")]]>
</dataSourceExpression>
</datasetRun>
<jr:listContents height="60" width="560">
<frame>
<reportElement positionType="Float" x="0" y="0" width="560" height="30" isRemoveLineWhenBlank="true" uuid="f063936c-ab95-465d-9501-0ed8e5d4dacc"/>
<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="0.0" lineStyle="Solid" lineColor="#000000"/>
</box>
<textField>
<reportElement positionType="Float" x="460" y="0" width="100" height="30" uuid="4c7e80d3-6bc4-4281-8c7f-2ba6ba18fa74">
<property name="com.jaspersoft.studio.unit.width" value="pixel"/>
<property name="com.jaspersoft.studio.unit.x" value="pixel"/>
<property name="com.jaspersoft.studio.unit.y" value="pixel"/>
</reportElement>
<box>
<topPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
<leftPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<bottomPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
<rightPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
</box>
<textFieldExpression>
<![CDATA[$F{itemId}]]>
</textFieldExpression>
</textField>
<textField>
<reportElement positionType="Float" x="30" y="0" width="330" height="30" uuid="96042aa9-402a-4a8f-b008-b3d0ff94becd">
<property name="com.jaspersoft.studio.unit.x" value="pixel"/>
</reportElement>
<box>
<topPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
<leftPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<bottomPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
<rightPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
</box>
<textFieldExpression>
<![CDATA[$F{name}]]>
</textFieldExpression>
</textField>
<textField>
<reportElement positionType="Float" x="360" y="0" width="100" height="30" uuid="2d3b1a7b-4bfb-4c12-bdaa-741af76a52fd">
<property name="com.jaspersoft.studio.unit.width" value="pixel"/>
<property name="com.jaspersoft.studio.unit.x" value="pixel"/>
<property name="com.jaspersoft.studio.unit.y" value="pixel"/>
</reportElement>
<box>
<topPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
<leftPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<bottomPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
<rightPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
</box>
<textFieldExpression>
<![CDATA[$F{childType}]]>
</textFieldExpression>
</textField>
</frame>
<frame>
<reportElement positionType="Float" stretchType="ContainerBottom" x="0" y="30" width="560" height="30" isRemoveLineWhenBlank="true" uuid="77c3cf69-01ec-41c0-86e0-9b81d17c6a75">
<property name="com.jaspersoft.studio.unit.y" value="pixel"/>
<property name="com.jaspersoft.studio.unit.x" value="pixel"/>
<property name="com.jaspersoft.studio.unit.height" value="pixel"/>
</reportElement>
<componentElement>
<reportElement key="" positionType="Float" stretchType="ContainerBottom" x="0" y="0" width="560" height="30" isRemoveLineWhenBlank="true" uuid="4bec04d5-cd1f-4236-8867-aeba9579161a">
<property name="com.jaspersoft.studio.unit.y" value="pixel"/>
<property name="com.jaspersoft.studio.unit.x" value="pixel"/>
<property name="net.sf.jasperreports.export.headertoolbar.table.name" value="CWI"/>
</reportElement>
<jr:list printOrder="Vertical">
<datasetRun subDataset="OrderItems" uuid="7517e1b5-fef5-4466-acdb-c83b082bbc1a">
<dataSourceExpression>
<![CDATA[((net.sf.jasperreports.engine.data.JRXmlDataSource)$P{REPORT_DATA_SOURCE}).dataSource("/xml/order/items/children/items[itemId='"+$F{itemId}+"']/children[childType='typeCWI']/items")]]>
</dataSourceExpression>
</datasetRun>
<jr:listContents height="30" width="560">
<frame>
<reportElement positionType="Float" stretchType="ContainerBottom" x="0" y="0" width="560" height="30" isRemoveLineWhenBlank="true" uuid="9fcf1658-09b4-4d40-983b-7934d6c44e43"/>
<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="0.0" lineStyle="Solid" lineColor="#000000"/>
</box>
<textField>
<reportElement positionType="Float" x="460" y="0" width="100" height="30" uuid="c51d6125-185c-4733-bcf2-a9828229b091">
<property name="com.jaspersoft.studio.unit.width" value="pixel"/>
<property name="com.jaspersoft.studio.unit.x" value="pixel"/>
<property name="com.jaspersoft.studio.unit.y" value="pixel"/>
</reportElement>
<box>
<topPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
<leftPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<bottomPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
<rightPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
</box>
<textFieldExpression>
<![CDATA[$F{itemId}]]>
</textFieldExpression>
</textField>
<textField>
<reportElement positionType="Float" x="60" y="0" width="300" height="30" uuid="5f06b7e6-7d49-4dee-832f-a5a35285a5a6">
<property name="com.jaspersoft.studio.unit.y" value="pixel"/>
<property name="com.jaspersoft.studio.unit.x" value="pixel"/>
</reportElement>
<box>
<topPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
<leftPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<bottomPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
<rightPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
</box>
<textFieldExpression>
<![CDATA[$F{name}]]>
</textFieldExpression>
</textField>
<textField>
<reportElement positionType="Float" x="360" y="0" width="100" height="30" uuid="259ab20e-a5e5-4fa1-ad8a-4cc602e57ad0">
<property name="com.jaspersoft.studio.unit.width" value="pixel"/>
<property name="com.jaspersoft.studio.unit.y" value="pixel"/>
<property name="com.jaspersoft.studio.unit.x" value="pixel"/>
</reportElement>
<box>
<topPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
<leftPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<bottomPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
<rightPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
</box>
<textFieldExpression>
<![CDATA[$F{childType}]]>
</textFieldExpression>
</textField>
</frame>
</jr:listContents>
</jr:list>
</componentElement>
</frame>
</jr:listContents>
</jr:list>
</componentElement>
</frame>
</frame>
</jr:listContents>
</jr:list>
</componentElement>
</frame>
</band>
</detail>
下面我将此报告导出为 .xls 格式并截取了屏幕截图,以说明我现在遇到的实际结果和期望的结果。
XLS 格式的实际结果屏幕截图(红色线条环绕不需要的白色 space):
所需结果的 XLS 格式屏幕截图:
当 IAR 项目的嵌套列表没有行(使用 "Remove Line When Blank" 选项”)或既没有 IAR- 也没有 SV-type 各自嵌套列表的行。但是,当 SV-type 项的列表为 non-empty 且 CWI-type 项为空时,白色 space 显示 CWI-type行将被定位。我尝试通过浮动所有报告组件(例如文本字段、列表、框架等)来删除不需要的白色 space,将所有报告组件的拉伸类型设置为 "ElementGroupBottom" 和 "ContainerBottom",但无济于事。
有谁知道我应该如何制作这份报告才能达到预期的结果?
您可以将 List SV 元素的高度减小到 30,同时将其单元格高度保留为 60。这样,当 List CWI 中没有数据时,单元格高度将保持为 30,但会拉伸到当 List CWI 产生行数时为 60 或更多。
缺点是 List CWI 在 Jaspersoft Sudio 的设计视图中会被遮挡,您只能通过向下钻取到 List SV 才能看到它。
更改如下:
- 将 List SV 单元格高度保留为 60
- 将 List SV 元素高度从 60 更改为 30(请注意,在此步骤中,Studio 可能会自动将单元格高度更改为 30,如果这样做,则将其设置回 60)
- 将放置 List SV 的框架的高度从 60 更改为 30
- 将父框架的高度从 90 更改为 60
- 将列表 G 的元素和单元格高度从 120 更改为 90
- 将细节带和顶层框架的高度从 120 更改为 90