我想打印一个包含 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="printWhenGroupChangesInTable" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="f3095c03-6622-4524-a0fc-9471ad06913a">
<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>
<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="New Dataset 1" uuid="9bf6fe22-d440-4db4-a496-8e0689a3cf35">
<field name="COLUMN_0" class="java.lang.String"/>
<field name="COLUMN_1" class="java.lang.String"/>
<field name="COLUMN_2" class="java.lang.String"/>
<sortField name="COLUMN_0"/>
<sortField name="COLUMN_1"/>
<group name="group">
<groupExpression><![CDATA[$F{COLUMN_0}]]></groupExpression>
</group>
<group name="subgroup">
<groupExpression><![CDATA[$F{COLUMN_1}]]></groupExpression>
</group>
</subDataset>
<detail>
<band height="20" splitType="Stretch">
<componentElement>
<reportElement uuid="e357d4bd-5ea9-49e6-ac22-161567bf6aea" key="table 1" style="table 1" x="0" y="0" width="555" height="20"/>
<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="New Dataset 1" uuid="cbc8c9a3-d793-420c-8bbb-37a3d0e540d5">
<dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.data.JRCsvDataSource("C:\\example.csv")]]></dataSourceExpression>
</datasetRun>
<jr:column width="185" uuid="3f354cfb-b31f-4c52-8103-d47891981e64">
<jr:detailCell style="table 1_TD" height="20" rowSpan="1">
<textField>
<reportElement uuid="699725e5-704a-4fe5-96e0-77eb57b7fc69" isPrintRepeatedValues="false" x="0" y="0" width="185" height="20" isPrintInFirstWholeBand="true" isPrintWhenDetailOverflows="true" printWhenGroupChanges="subgroup"/>
<textElement/>
<textFieldExpression><![CDATA[$F{COLUMN_0}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
<jr:column width="185" uuid="8046b163-8e37-489d-a9fd-2ef02c26c7d5">
<jr:detailCell style="table 1_TD" height="20" rowSpan="1">
<textField>
<reportElement uuid="537ee40d-36f4-42ff-99b1-ae3db1497384" isPrintRepeatedValues="false" x="0" y="0" width="185" height="20" isPrintInFirstWholeBand="true" isPrintWhenDetailOverflows="true" printWhenGroupChanges="subgroup"/>
<textElement/>
<textFieldExpression><![CDATA[$F{COLUMN_1}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
<jr:column width="185" uuid="9805e883-8dce-4e6b-b5a3-fc2249969e33">
<jr:detailCell style="table 1_TD" height="20" rowSpan="1">
<textField>
<reportElement uuid="b94b64a6-daa0-4cb5-8bcb-7fa0ab2d85dc" x="0" y="0" width="185" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[$F{COLUMN_2}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
</jr:table>
</componentElement>
</band>
</detail>
</jasperReport>
和样本数据:
group1,subgroup1,value1
group1,subgroup1,value2
group1,subgroup1,value3
group1,subgroup2,value1
group1,subgroup2,value2
group1,subgroup2,value3
group2,subgroup1,value1
group2,subgroup1,value2
group2,subgroup1,value3
group2,subgroup2,value1
group2,subgroup2,value2
group2,subgroup2,value3
group3,subgroup2,value1
我的期望:
组 1 子组 1 值 1 价值2 价值3 组 1 子组 2 值 1 价值2 价值3 组 2 子组 1 值 1 价值2 价值3 组 2 子组 2 值 1 价值2 价值3 组 3 子组 2 值 1
我得到什么:
组 1 子组 1 值 1 价值2 价值3 子组 2 值 1 价值2 价值3 组 2 子组 1 值 1 价值2 价值3 子组 2 值 1 价值2 价值3 组 3 值 1
两个 textFiled 都标有 printWhenGroupChanges="subgroup"。
我不想使用 printWhenExpression: $V{subgroup_COUNT}==1 因为这样 isPrintInFirstWholeBand="true" 没有被考虑在内,并且 [group, subgroup] 连音不会打印在新页面的顶部。
我已经在 jasper 网站上做了一个错误报告:错误报告。
有谁知道我该如何解决这个问题?