0

我的 Jasper Report 运行查询并完美地获取数据。数据显示在表格组件中并导出到 Excel 文件。

我的问题是,包含数据的表格组件被打印了多次(大约 20 次)。我不知道为什么会这样。

我对 Jasper Reports 比较陌生(我已经学习了一周),所以我很可能会遗漏一些东西。

以下是jrxml文件:

<?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="projectbycustomerreport" pageWidth="752" pageHeight="572" orientation="Landscape" whenNoDataType="AllSectionsNoDetail" columnWidth="752" leftMargin="0" rightMargin="0" topMargin="0" bottomMargin="0" uuid="476a09b7-7823-4320-aaa0-3721aee471cc">
<property name="ireport.zoom" value="1.0"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="94"/>
<subDataset name="TableDataset" uuid="09d8857b-956c-490e-b34d-72860983bdf9">
    <parameter name="DATE_FROM" class="java.lang.String" isForPrompting="false"/>
    <parameter name="DATE_TO" class="java.lang.String" isForPrompting="false"/>
    <parameter name="MAIN_CUST_NUM" class="java.lang.String" isForPrompting="false"/>
    <parameter name="MAIN_PROJ_NUM" class="java.lang.Integer" isForPrompting="false"/>
    <queryString>
        <![CDATA[SELECT TSDATE, TSCONO, TSCSNO, TSDEPT, TSPRNO, TSPHAS, TSMSNO, TSTASK, ITEM, TSSRNO, TSPSAN, TSWONO, TSSIRN, TSTSKH, TSBILH, TSNBHC, TSNBHI, TSTRFH, TSOTHH, TSTRVT, TSMILE, TSCCNM FROM WeeklyTimesheetTable WHERE((TSDATE BETWEEN CONVERT(date,$P{DATE_FROM}) AND CONVERT(date,$P{DATE_TO})) AND (TSCSNO=$P{MAIN_CUST_NUM}) AND (TSPRNO=$P{MAIN_PROJ_NUM}))]]>
    </queryString>
    <field name="TSDATE" class="java.lang.String"/>
    <field name="TSCONO" class="java.lang.Integer"/>
    <field name="TSCSNO" class="java.lang.String"/>
    <field name="TSDEPT" class="java.lang.String"/>
    <field name="TSPRNO" class="java.lang.Integer"/>
    <field name="TSPHAS" class="java.lang.Integer"/>
    <field name="TSMSNO" class="java.lang.Double"/>
    <field name="TSTASK" class="java.lang.Double"/>
    <field name="ITEM" class="java.lang.String"/>
    <field name="TSSRNO" class="java.lang.String"/>
    <field name="TSPSAN" class="java.lang.String"/>
    <field name="TSWONO" class="java.lang.String"/>
    <field name="TSSIRN" class="java.lang.String"/>
    <field name="TSTSKH" class="java.lang.Double"/>
    <field name="TSBILH" class="java.lang.Double"/>
    <field name="TSNBHC" class="java.lang.Double"/>
    <field name="TSNBHI" class="java.lang.Double"/>
    <field name="TSTRFH" class="java.lang.Double"/>
    <field name="TSOTHH" class="java.lang.Double"/>
    <field name="TSTRVT" class="java.lang.Double"/>
    <field name="TSMILE" class="java.lang.Double"/>
    <field name="TSCCNM" class="java.lang.String"/>
    <sortField name="TSCONO"/>
    <sortField name="TSDATE"/>
</subDataset>
<parameter name="CUST_ID" class="java.lang.String" isForPrompting="false"/>
<parameter name="PROJ_ID" class="java.lang.String" isForPrompting="false"/>
<parameter name="DATE_FROM" class="java.lang.String" isForPrompting="false"/>
<parameter name="DATE_TO" class="java.lang.String" isForPrompting="false"/>
<parameter name="DATE_GEN" class="java.lang.String" isForPrompting="false"/>
<parameter name="TIME_GEN" class="java.lang.String" isForPrompting="false"/>
<parameter name="MAIN_PROJ_NUM" class="java.lang.Integer" isForPrompting="false"/>
<parameter name="MAIN_CUST_NUM" class="java.lang.String" isForPrompting="false"/>
<queryString>
    <![CDATA[SELECT TSDATE, TSCONO, TSCSNO, TSDEPT, TSPRNO, TSPHAS, TSMSNO, TSTASK, ITEM, TSSRNO, TSPSAN, TSWONO, TSSIRN, TSTSKH, TSBILH, TSNBHC, TSNBHI, TSTRFH, TSOTHH, TSTRVT, TSMILE, TSCCNM FROM WeeklyTimesheetTable WHERE((TSDATE BETWEEN CONVERT(date,$P{DATE_FROM}) AND CONVERT(date,$P{DATE_TO})) AND (TSCSNO=$P{MAIN_CUST_NUM}) AND (TSPRNO=$P{MAIN_PROJ_NUM}))]]>
</queryString>
<field name="TSDATE" class="java.lang.String"/>
<field name="TSCONO" class="java.lang.Integer"/>
<field name="TSCSNO" class="java.lang.String"/>
<field name="TSDEPT" class="java.lang.String"/>
<field name="TSPRNO" class="java.lang.Integer"/>
<field name="TSPHAS" class="java.lang.Integer"/>
<field name="TSMSNO" class="java.lang.Double"/>
<field name="TSTASK" class="java.lang.Double"/>
<field name="ITEM" class="java.lang.String"/>
<field name="TSSRNO" class="java.lang.String"/>
<field name="TSPSAN" class="java.lang.String"/>
<field name="TSWONO" class="java.lang.String"/>
<field name="TSSIRN" class="java.lang.String"/>
<field name="TSTSKH" class="java.lang.Double"/>
<field name="TSBILH" class="java.lang.Double"/>
<field name="TSNBHC" class="java.lang.Double"/>
<field name="TSNBHI" class="java.lang.Double"/>
<field name="TSTRFH" class="java.lang.Double"/>
<field name="TSOTHH" class="java.lang.Double"/>
<field name="TSTRVT" class="java.lang.Double"/>
<field name="TSMILE" class="java.lang.Double"/>
<field name="TSCCNM" class="java.lang.String"/>
<background>
    <band splitType="Stretch"/>
</background>
<title>
    <band height="191" splitType="Stretch">
        <frame>
            <reportElement uuid="a64247fb-c0f0-4ed8-9d4b-d086199fdee5" stretchType="RelativeToBandHeight" mode="Opaque" x="0" y="4" width="752" height="32" forecolor="#000000" backcolor="#3399FF"/>
            <box>
                <topPen lineWidth="1.0" lineStyle="Solid"/>
                <leftPen lineWidth="1.0" lineStyle="Solid"/>
                <bottomPen lineWidth="1.0" lineStyle="Solid"/>
                <rightPen lineWidth="1.0" lineStyle="Solid"/>
            </box>
            <staticText>
                <reportElement uuid="70fc51ae-580a-4a3d-961e-db5a2f8f6991" mode="Transparent" x="0" y="0" width="752" height="32" forecolor="#000000"/>
                <textElement textAlignment="Center">
                    <font fontName="Arial" size="24" isBold="true"/>
                </textElement>
                <text><![CDATA[Project By Customer Report]]></text>
            </staticText>
        </frame>
        <frame>
            <reportElement uuid="79506db1-e406-4f92-9014-775900b6bba8" mode="Opaque" x="0" y="36" width="752" height="140" backcolor="#CCCCCC"/>
            <box>
                <topPen lineWidth="1.0" lineStyle="Solid"/>
                <leftPen lineWidth="1.0" lineStyle="Solid"/>
                <bottomPen lineWidth="1.0" lineStyle="Solid"/>
                <rightPen lineWidth="1.0" lineStyle="Solid"/>
            </box>
            <staticText>
                <reportElement uuid="6e97c9f7-360a-4476-bdc0-2f68f2c4aa17" x="0" y="5" width="150" height="20"/>
                <textElement>
                    <font fontName="Arial" size="12" isBold="true"/>
                </textElement>
                <text><![CDATA[Customer ID & Name:]]></text>
            </staticText>
            <staticText>
                <reportElement uuid="43f905dc-3c9d-42f3-96fd-089b46678c8d" x="0" y="32" width="150" height="20"/>
                <textElement>
                    <font fontName="Arial" size="12" isBold="true"/>
                </textElement>
                <text><![CDATA[Project ID & Name:]]></text>
            </staticText>
            <staticText>
                <reportElement uuid="0f6002cb-b314-44c3-8d3b-979512fd0bac" x="0" y="60" width="150" height="20"/>
                <textElement>
                    <font fontName="Arial" size="12" isBold="true"/>
                </textElement>
                <text><![CDATA[Period:]]></text>
            </staticText>
            <staticText>
                <reportElement uuid="5699709c-40df-44d4-9c27-df1f48de225b" x="0" y="88" width="150" height="20"/>
                <textElement>
                    <font fontName="Arial" size="12" isBold="true"/>
                </textElement>
                <text><![CDATA[Date Generated:]]></text>
            </staticText>
            <staticText>
                <reportElement uuid="c53d2360-f096-41b2-990e-27beb8608b4b" x="0" y="116" width="150" height="20"/>
                <textElement>
                    <font fontName="Arial" size="12" isBold="true"/>
                </textElement>
                <text><![CDATA[Time Generated:]]></text>
            </staticText>
            <textField>
                <reportElement uuid="02cf4c1b-53e4-46e9-80bd-9513012ad35e" x="150" y="5" width="602" height="20"/>
                <textElement>
                    <font fontName="Arial" size="12" isBold="true"/>
                </textElement>
                <textFieldExpression><![CDATA[$P{CUST_ID}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement uuid="ad104c49-6300-4897-b2bc-7147bdab5bca" x="150" y="32" width="602" height="20"/>
                <textElement>
                    <font fontName="Arial" size="12" isBold="true"/>
                </textElement>
                <textFieldExpression><![CDATA[$P{PROJ_ID}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement uuid="c56252dc-3713-4d49-99a8-df6a3ea056a0" x="150" y="88" width="100" height="20"/>
                <textElement>
                    <font fontName="Arial" size="12" isBold="true"/>
                </textElement>
                <textFieldExpression><![CDATA[$P{DATE_GEN}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement uuid="cdf7af05-739a-4086-8d38-9fb3e0f45b35" x="150" y="116" width="226" height="20"/>
                <textElement>
                    <font fontName="Arial" size="12" isBold="true"/>
                </textElement>
                <textFieldExpression><![CDATA[$P{TIME_GEN}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement uuid="94b1054e-ff88-4b6b-ac53-5e9caa4ed0a3" x="150" y="60" width="100" height="20"/>
                <textElement>
                    <font fontName="Arial" size="12" isBold="true"/>
                </textElement>
                <textFieldExpression><![CDATA[$P{DATE_FROM}]]></textFieldExpression>
            </textField>
            <staticText>
                <reportElement uuid="238f5e67-19f3-40c4-a9c2-b2ec1bbcbd32" x="250" y="60" width="26" height="20"/>
                <textElement>
                    <font fontName="Arial" size="12" isBold="true"/>
                </textElement>
                <text><![CDATA[to]]></text>
            </staticText>
            <textField>
                <reportElement uuid="c119a6d7-b873-4d2e-bdbf-4482454b67d6" x="276" y="60" width="100" height="20"/>
                <textElement>
                    <font fontName="Arial" size="12" isBold="true"/>
                </textElement>
                <textFieldExpression><![CDATA[$P{DATE_TO}]]></textFieldExpression>
            </textField>
        </frame>
    </band>
</title>
<detail>
    <band height="572" splitType="Stretch">
        <componentElement>
            <reportElement uuid="0f51d841-bb5b-4775-9b87-03ba695a6971" key="table 2" style="mainTable" x="0" y="0" width="752" height="572"/>
            <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" whenNoDataType="AllSectionsNoDetail">
                <datasetRun subDataset="TableDataset" uuid="7d17fcfc-0541-4e5e-9a72-86649e38cd06">
                    <datasetParameter name="DATE_FROM">
                        <datasetParameterExpression><![CDATA[$P{DATE_FROM}]]></datasetParameterExpression>
                    </datasetParameter>
                    <datasetParameter name="DATE_TO">
                        <datasetParameterExpression><![CDATA[$P{DATE_TO}]]></datasetParameterExpression>
                    </datasetParameter>
                    <datasetParameter name="MAIN_CUST_NUM">
                        <datasetParameterExpression><![CDATA[$P{MAIN_CUST_NUM}]]></datasetParameterExpression>
                    </datasetParameter>
                    <datasetParameter name="MAIN_PROJ_NUM">
                        <datasetParameterExpression><![CDATA[$P{MAIN_PROJ_NUM}]]></datasetParameterExpression>
                    </datasetParameter>
                    <connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
                </datasetRun>
                <jr:column width="90" uuid="d375f5a3-db9e-450d-8ac2-e1a9a6fc18fc">
                    <jr:columnHeader style="table_CH" height="30">
                        <staticText>
                            <reportElement uuid="4cd206f2-6591-41a5-969c-9466034aac24" x="0" y="0" width="90" height="30"/>
                            <textElement/>
                            <text><![CDATA[TSDATE]]></text>
                        </staticText>
                    </jr:columnHeader>
                    <jr:detailCell style="table_TD" height="20">
                        <textField>
                            <reportElement uuid="47c0d3dd-aac2-44ff-a3e5-426cd092fd54" x="0" y="0" width="90" height="20"/>
                            <textElement/>
                            <textFieldExpression><![CDATA[$F{TSDATE}]]></textFieldExpression>
                        </textField>
                    </jr:detailCell>
                </jr:column>
                <jr:column width="90" uuid="587ce56a-9008-43be-b850-dc5397b81c3a">
                    <jr:columnHeader style="table_CH" height="30">
                        <staticText>
                            <reportElement uuid="73460bc8-c487-4712-8a50-99f624a6bab5" x="0" y="0" width="90" height="30"/>
                            <textElement/>
                            <text><![CDATA[TSCONO]]></text>
                        </staticText>
                    </jr:columnHeader>
                    <jr:detailCell style="table_TD" height="20">
                        <textField>
                            <reportElement uuid="ce6aaaad-562e-4e8f-9841-d51759e57035" x="0" y="0" width="90" height="20"/>
                            <textElement/>
                            <textFieldExpression><![CDATA[$F{TSCONO}]]></textFieldExpression>
                        </textField>
                    </jr:detailCell>
                </jr:column>
                <jr:column width="90" uuid="83d4280b-05a0-425e-a49c-f7eccc1880bf">
                    <jr:columnHeader style="table_CH" height="30">
                        <staticText>
                            <reportElement uuid="834e3ec6-bdb8-46f5-99e5-9953a615f382" x="0" y="0" width="90" height="30"/>
                            <textElement/>
                            <text><![CDATA[TSCSNO]]></text>
                        </staticText>
                    </jr:columnHeader>
                    <jr:detailCell style="table_TD" height="20">
                        <textField>
                            <reportElement uuid="584eadf1-ab41-44b6-9453-1c2fe27f329c" x="0" y="0" width="90" height="20"/>
                            <textElement/>
                            <textFieldExpression><![CDATA[$F{TSCSNO}]]></textFieldExpression>
                        </textField>
                    </jr:detailCell>
                </jr:column>
                <jr:column width="90" uuid="076aa9f0-5519-4c17-a0d0-43263458e17f">
                    <jr:columnHeader style="table_CH" height="30">
                        <staticText>
                            <reportElement uuid="2cbbc5b0-a585-4ee2-8f48-a7c336ca090e" x="0" y="0" width="90" height="30"/>
                            <textElement/>
                            <text><![CDATA[TSDEPT]]></text>
                        </staticText>
                    </jr:columnHeader>
                    <jr:detailCell style="table_TD" height="20">
                        <textField>
                            <reportElement uuid="fdf84ff5-50b9-4ec8-b849-0bf4de80a7a7" x="0" y="0" width="90" height="20"/>
                            <textElement/>
                            <textFieldExpression><![CDATA[$F{TSDEPT}]]></textFieldExpression>
                        </textField>
                    </jr:detailCell>
                </jr:column>
                <jr:column width="90" uuid="bc1af644-0380-4abe-bc32-8e130d24ffdf">
                    <jr:columnHeader style="table_CH" height="30">
                        <staticText>
                            <reportElement uuid="3c0ebe11-a46a-421c-b312-99022544ca2a" x="0" y="0" width="90" height="30"/>
                            <textElement/>
                            <text><![CDATA[TSPRNO]]></text>
                        </staticText>
                    </jr:columnHeader>
                    <jr:detailCell style="table_TD" height="20">
                        <textField>
                            <reportElement uuid="6e028901-0e32-4467-9387-79eefb3d54fc" x="0" y="0" width="90" height="20"/>
                            <textElement/>
                            <textFieldExpression><![CDATA[$F{TSPRNO}]]></textFieldExpression>
                        </textField>
                    </jr:detailCell>
                </jr:column>
                <jr:column width="90" uuid="6ba32984-eeba-4b3c-815d-1c041a04bb08">
                    <jr:columnHeader style="table_CH" height="30">
                        <staticText>
                            <reportElement uuid="7d6f0145-27c8-4f23-9e05-8a2c3714dfc7" x="0" y="0" width="90" height="30"/>
                            <textElement/>
                            <text><![CDATA[TSPHAS]]></text>
                        </staticText>
                    </jr:columnHeader>
                    <jr:detailCell style="table_TD" height="20">
                        <textField>
                            <reportElement uuid="757f479d-f624-403f-94b2-a1a7f5deff21" x="0" y="0" width="90" height="20"/>
                            <textElement/>
                            <textFieldExpression><![CDATA[$F{TSPHAS}]]></textFieldExpression>
                        </textField>
                    </jr:detailCell>
                </jr:column>
                <jr:column width="90" uuid="91e6bf63-edaf-4795-8e86-74a1b0c36e82">
                    <jr:columnHeader style="table_CH" height="30">
                        <staticText>
                            <reportElement uuid="9687b2b4-4c0d-4771-96e5-906481ec8bae" x="0" y="0" width="90" height="30"/>
                            <textElement/>
                            <text><![CDATA[TSMSNO]]></text>
                        </staticText>
                    </jr:columnHeader>
                    <jr:detailCell style="table_TD" height="20">
                        <textField>
                            <reportElement uuid="1efbda7d-3eb4-4f9e-9e01-04932ce2c518" x="0" y="0" width="90" height="20"/>
                            <textElement/>
                            <textFieldExpression><![CDATA[$F{TSMSNO}]]></textFieldExpression>
                        </textField>
                    </jr:detailCell>
                </jr:column>
                <jr:column width="90" uuid="a5280cec-20f6-4f6b-978e-e6b9c8791e9a">
                    <jr:columnHeader style="table_CH" height="30">
                        <staticText>
                            <reportElement uuid="3d4e6cac-734d-4944-9723-f5ecdd9cff8e" x="0" y="0" width="90" height="30"/>
                            <textElement/>
                            <text><![CDATA[TSTASK]]></text>
                        </staticText>
                    </jr:columnHeader>
                    <jr:detailCell style="table_TD" height="20">
                        <textField>
                            <reportElement uuid="10c3896f-7c7a-443f-ae9a-fb6834d930a6" x="0" y="0" width="90" height="20"/>
                            <textElement/>
                            <textFieldExpression><![CDATA[$F{TSTASK}]]></textFieldExpression>
                        </textField>
                    </jr:detailCell>
                </jr:column>
                <jr:column width="90" uuid="2780dc1e-fec7-4366-b97d-2bed6556b8ab">
                    <jr:columnHeader style="table_CH" height="30">
                        <staticText>
                            <reportElement uuid="955b38e6-caf2-4952-9601-97fd88f61a9d" x="0" y="0" width="90" height="30"/>
                            <textElement/>
                            <text><![CDATA[ITEM]]></text>
                        </staticText>
                    </jr:columnHeader>
                    <jr:detailCell style="table_TD" height="20">
                        <textField>
                            <reportElement uuid="e97694ca-dae7-40df-9b53-8aeeb138e546" x="0" y="0" width="90" height="20"/>
                            <textElement/>
                            <textFieldExpression><![CDATA[$F{ITEM}]]></textFieldExpression>
                        </textField>
                    </jr:detailCell>
                </jr:column>
                <jr:column width="90" uuid="02111dc5-db46-4f99-a7c6-b26723cc1847">
                    <jr:columnHeader style="table_CH" height="30">
                        <staticText>
                            <reportElement uuid="2615591e-7a96-47cf-9ca0-be9a563bf1b4" x="0" y="0" width="90" height="30"/>
                            <textElement/>
                            <text><![CDATA[TSSRNO]]></text>
                        </staticText>
                    </jr:columnHeader>
                    <jr:detailCell style="table_TD" height="20">
                        <textField>
                            <reportElement uuid="694bcb7f-f283-4b62-a6ff-649fe4ab72c2" x="0" y="0" width="90" height="20"/>
                            <textElement/>
                            <textFieldExpression><![CDATA[$F{TSSRNO}]]></textFieldExpression>
                        </textField>
                    </jr:detailCell>
                </jr:column>
                <jr:column width="90" uuid="52fc695f-50db-4bea-aef7-ad2cd7c9f108">
                    <jr:columnHeader style="table_CH" height="30">
                        <staticText>
                            <reportElement uuid="eacf6552-ac9e-4450-9f15-7a237c6cfec8" x="0" y="0" width="90" height="30"/>
                            <textElement/>
                            <text><![CDATA[TSPSAN]]></text>
                        </staticText>
                    </jr:columnHeader>
                    <jr:detailCell style="table_TD" height="20">
                        <textField>
                            <reportElement uuid="3a61da59-d709-4776-b805-e3b261f76786" x="0" y="0" width="90" height="20"/>
                            <textElement/>
                            <textFieldExpression><![CDATA[$F{TSPSAN}]]></textFieldExpression>
                        </textField>
                    </jr:detailCell>
                </jr:column>
                <jr:column width="90" uuid="af9ce744-f683-4a3e-a75a-0ce9e58ab288">
                    <jr:columnHeader style="table_CH" height="30">
                        <staticText>
                            <reportElement uuid="09e9bafe-84b1-4837-9fff-e028570c2aba" x="0" y="0" width="90" height="30"/>
                            <textElement/>
                            <text><![CDATA[TSWONO]]></text>
                        </staticText>
                    </jr:columnHeader>
                    <jr:detailCell style="table_TD" height="20">
                        <textField>
                            <reportElement uuid="6cde712a-24db-4099-b602-7f05b87f38ad" x="0" y="0" width="90" height="20"/>
                            <textElement/>
                            <textFieldExpression><![CDATA[$F{TSWONO}]]></textFieldExpression>
                        </textField>
                    </jr:detailCell>
                </jr:column>
                <jr:column width="90" uuid="a2c49ac5-3f2a-4bd3-a4d8-30efd4163beb">
                    <jr:columnHeader style="table_CH" height="30">
                        <staticText>
                            <reportElement uuid="5d992a75-c66e-49ce-9f2a-09769ac751c1" x="0" y="0" width="90" height="30"/>
                            <textElement/>
                            <text><![CDATA[TSSIRN]]></text>
                        </staticText>
                    </jr:columnHeader>
                    <jr:detailCell style="table_TD" height="20">
                        <textField>
                            <reportElement uuid="2dd04d7f-6477-45f7-b013-568d3ad0db26" x="0" y="0" width="90" height="20"/>
                            <textElement/>
                            <textFieldExpression><![CDATA[$F{TSSIRN}]]></textFieldExpression>
                        </textField>
                    </jr:detailCell>
                </jr:column>
                <jr:column width="90" uuid="3484cb89-dd95-49eb-8c85-afc7567ed5bc">
                    <jr:columnHeader style="table_CH" height="30">
                        <staticText>
                            <reportElement uuid="7bdbb4e4-8fb8-4706-9fc2-5f5b85aac79e" x="0" y="0" width="90" height="30"/>
                            <textElement/>
                            <text><![CDATA[TSTSKH]]></text>
                        </staticText>
                    </jr:columnHeader>
                    <jr:detailCell style="table_TD" height="20">
                        <textField>
                            <reportElement uuid="09ec98f7-b2e4-438a-9a8d-7dd51db70cba" x="0" y="0" width="90" height="20"/>
                            <textElement/>
                            <textFieldExpression><![CDATA[$F{TSTSKH}]]></textFieldExpression>
                        </textField>
                    </jr:detailCell>
                </jr:column>
                <jr:column width="90" uuid="ad93e1c3-e4ac-4367-a31e-440eddf776cd">
                    <jr:columnHeader style="table_CH" height="30">
                        <staticText>
                            <reportElement uuid="3446f9bd-a05b-4574-a9a8-0f59ebdfed4e" x="0" y="0" width="90" height="30"/>
                            <textElement/>
                            <text><![CDATA[TSBILH]]></text>
                        </staticText>
                    </jr:columnHeader>
                    <jr:detailCell style="table_TD" height="20">
                        <textField>
                            <reportElement uuid="cbcab416-75b2-4706-bfb1-d34ff6323b18" x="0" y="0" width="90" height="20"/>
                            <textElement/>
                            <textFieldExpression><![CDATA[$F{TSBILH}]]></textFieldExpression>
                        </textField>
                    </jr:detailCell>
                </jr:column>
                <jr:column width="90" uuid="1b4fdc9d-5c59-4443-a7c8-6e5edd51ad75">
                    <jr:columnHeader style="table_CH" height="30">
                        <staticText>
                            <reportElement uuid="d57feffc-245b-4bc7-85e4-38e8396c837e" x="0" y="0" width="90" height="30"/>
                            <textElement/>
                            <text><![CDATA[TSNBHC]]></text>
                        </staticText>
                    </jr:columnHeader>
                    <jr:detailCell style="table_TD" height="20">
                        <textField>
                            <reportElement uuid="89731118-1073-48e3-a321-76a316c28b55" x="0" y="0" width="90" height="20"/>
                            <textElement/>
                            <textFieldExpression><![CDATA[$F{TSNBHC}]]></textFieldExpression>
                        </textField>
                    </jr:detailCell>
                </jr:column>
                <jr:column width="90" uuid="93186b6f-adb3-4861-a503-4e782bf837b2">
                    <jr:columnHeader style="table_CH" height="30">
                        <staticText>
                            <reportElement uuid="bbefa769-4e52-4f96-bb54-c4d019651d8b" x="0" y="0" width="90" height="30"/>
                            <textElement/>
                            <text><![CDATA[TSNBHI]]></text>
                        </staticText>
                    </jr:columnHeader>
                    <jr:detailCell style="table_TD" height="20">
                        <textField>
                            <reportElement uuid="a257d745-f999-4826-b210-b60b7a871343" x="0" y="0" width="90" height="20"/>
                            <textElement/>
                            <textFieldExpression><![CDATA[$F{TSNBHI}]]></textFieldExpression>
                        </textField>
                    </jr:detailCell>
                </jr:column>
                <jr:column width="90" uuid="89f3dea3-c95e-4099-bf3c-b1998a04b08c">
                    <jr:columnHeader style="table_CH" height="30">
                        <staticText>
                            <reportElement uuid="4c405fd9-1210-40fd-9ca4-c298f81d842b" x="0" y="0" width="90" height="30"/>
                            <textElement/>
                            <text><![CDATA[TSTRFH]]></text>
                        </staticText>
                    </jr:columnHeader>
                    <jr:detailCell style="table_TD" height="20">
                        <textField>
                            <reportElement uuid="bf152421-b30e-46c0-aec5-59330e8c39d6" x="0" y="0" width="90" height="20"/>
                            <textElement/>
                            <textFieldExpression><![CDATA[$F{TSTRFH}]]></textFieldExpression>
                        </textField>
                    </jr:detailCell>
                </jr:column>
                <jr:column width="90" uuid="f1584ffe-d3a0-4716-9fd8-8304fb4e612d">
                    <jr:columnHeader style="table_CH" height="30">
                        <staticText>
                            <reportElement uuid="ee774f5c-e8b1-4c41-8df3-912b68f88970" x="0" y="0" width="90" height="30"/>
                            <textElement/>
                            <text><![CDATA[TSOTHH]]></text>
                        </staticText>
                    </jr:columnHeader>
                    <jr:detailCell style="table_TD" height="20">
                        <textField>
                            <reportElement uuid="5324f7a9-8001-4537-b239-a3763aeda84e" x="0" y="0" width="90" height="20"/>
                            <textElement/>
                            <textFieldExpression><![CDATA[$F{TSOTHH}]]></textFieldExpression>
                        </textField>
                    </jr:detailCell>
                </jr:column>
                <jr:column width="90" uuid="e66738ed-9531-446b-a628-412161414eda">
                    <jr:columnHeader style="table_CH" height="30">
                        <staticText>
                            <reportElement uuid="37b96194-8dde-4a13-a2c9-1ed2a78c8f51" x="0" y="0" width="90" height="30"/>
                            <textElement/>
                            <text><![CDATA[TSTRVT]]></text>
                        </staticText>
                    </jr:columnHeader>
                    <jr:detailCell style="table_TD" height="20">
                        <textField>
                            <reportElement uuid="a4b7814a-ae7b-4b7b-adca-eac9bbe9abec" x="0" y="0" width="90" height="20"/>
                            <textElement/>
                            <textFieldExpression><![CDATA[$F{TSTRVT}]]></textFieldExpression>
                        </textField>
                    </jr:detailCell>
                </jr:column>
                <jr:column width="90" uuid="58ce548b-0fc0-4ca7-901f-4aa76fd24a6e">
                    <jr:columnHeader style="table_CH" height="30">
                        <staticText>
                            <reportElement uuid="9e7d4717-6a96-44cc-940a-7821b306713a" x="0" y="0" width="90" height="30"/>
                            <textElement/>
                            <text><![CDATA[TSMILE]]></text>
                        </staticText>
                    </jr:columnHeader>
                    <jr:detailCell style="table_TD" height="20">
                        <textField>
                            <reportElement uuid="e4124f5e-8538-4243-8a35-204e515d02e9" x="0" y="0" width="90" height="20"/>
                            <textElement/>
                            <textFieldExpression><![CDATA[$F{TSMILE}]]></textFieldExpression>
                        </textField>
                    </jr:detailCell>
                </jr:column>
                <jr:column width="90" uuid="7e7203e2-0707-4c7a-9e8e-f3a568387a20">
                    <jr:columnHeader style="table_CH" height="30">
                        <staticText>
                            <reportElement uuid="082ae041-bbd5-42c3-bedd-2efd715bbe54" x="0" y="0" width="90" height="30"/>
                            <textElement/>
                            <text><![CDATA[TSCCNM]]></text>
                        </staticText>
                    </jr:columnHeader>
                    <jr:detailCell style="table_TD" height="20">
                        <textField>
                            <reportElement uuid="a4e5d07e-c19c-4760-a0fd-415830172292" x="0" y="0" width="90" height="20"/>
                            <textElement/>
                            <textFieldExpression><![CDATA[$F{TSCCNM}]]></textFieldExpression>
                        </textField>
                    </jr:detailCell>
                </jr:column>
            </jr:table>
        </componentElement>
    </band>
</detail>
</jasperReport>

以下是我用来练习的测试Java程序的代码:

public class JasperReporter {

private Connection sqlConnection;
private JasperReport report;
private JasperPrint printer;
private JRXlsExporter exporter;

public JasperReporter() {
    com.microsoft.sqlserver.jdbc.SQLServerDataSource ds = new com.microsoft.sqlserver.jdbc.SQLServerDataSource();
    ds.setDatabaseName("TimesheetControlSystem");
    ds.setServerName("192.168.0.88");
    ds.setPortNumber(1433);
    ds.setPassword("*****");
    ds.setUser("tester");
    try {
        if ((this.sqlConnection = ds.getConnection()) == null) {
            javax.swing.JOptionPane.showMessageDialog(null, "Login Failed.", "Connection Status", javax.swing.JOptionPane.ERROR_MESSAGE);
        }
    } catch (SQLServerException ex) {
        Logger.getLogger(JasperReporter.class.getName()).log(Level.SEVERE, null, ex);
    }
}

public void createReport() {
    try {
        this.report = JasperCompileManager.compileReport("F:\\Local Documents\\Programming Projects\\Java\\Testing Projects\\JasperReporter\\projectbycustomerreport.jrxml");
        HashMap param = new HashMap();
        param.put("PROJ_ID", "9000: Internal");
        param.put("CUST_ID", "9055097252: Test");

        param.put("DATE_FROM", "2013-01-01");
        param.put("DATE_TO", "2013-01-28");

        param.put("DATE_GEN", "2013-01-30");
        param.put("TIME_GEN", "1:28 PM");

        param.put("MAIN_CUST_NUM", "1036066254");
        param.put("MAIN_PROJ_NUM", new Integer(9000));

        this.printer = JasperFillManager.fillReport(report, param, this.sqlConnection);

        this.exporter = new JRXlsExporter();
        this.exporter.setParameter(JRXlsExporterParameter.JASPER_PRINT, this.printer);
        this.exporter.setParameter(JRXlsExporterParameter.OUTPUT_FILE, new File("F:\\Local Documents\\Programming Projects\\Java\\Testing Projects\\JasperReporter\\jasperxls.xls"));
        this.exporter.setParameter(JRXlsExporterParameter.IS_DETECT_CELL_TYPE, Boolean.TRUE);
        this.exporter.setParameter(JRXlsExporterParameter.IS_WHITE_PAGE_BACKGROUND, Boolean.FALSE);
        this.exporter.setParameter(JRXlsExporterParameter.IS_REMOVE_EMPTY_SPACE_BETWEEN_ROWS, Boolean.TRUE);
        this.exporter.exportReport();
    } catch (JRException ex) {
        Logger.getLogger(JasperReporter.class.getName()).log(Level.SEVERE, null, ex);
    }
}

public static void main(String[] args) {
    jasperreporter.JasperReporter jr = new jasperreporter.JasperReporter();
    jr.createReport();
}
}

感谢您的任何帮助。

4

1 回答 1

2

You added the table component in the detail band, whereby you also have a main report query. The detail band gets rendered as often as there are rows in the result set for the main report query. Move the table in the summary band of the report, then it will be only rendered once.

<summary>
    <band height="138">
        <componentElement>
            <reportElement uuid="0f51d841-bb5b-4775-9b87-03ba695a6971" key="table 2" x="0" y="0" width="752" height="138"/>
            <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" whenNoDataType="AllSectionsNoDetail">
                <datasetRun subDataset="TableDataset" uuid="7d17fcfc-0541-4e5e-9a72-86649e38cd06">
                    <datasetParameter name="DATE_FROM">
                        <datasetParameterExpression><![CDATA[$P{DATE_FROM}]]></datasetParameterExpression>
                    </datasetParameter>
                    <datasetParameter name="DATE_TO">
                        <datasetParameterExpression><![CDATA[$P{DATE_TO}]]></datasetParameterExpression>
                    </datasetParameter>
                    <datasetParameter name="MAIN_CUST_NUM">
                        <datasetParameterExpression><![CDATA[$P{MAIN_CUST_NUM}]]></datasetParameterExpression>
                    </datasetParameter>
                    <datasetParameter name="MAIN_PROJ_NUM">
                        <datasetParameterExpression><![CDATA[$P{MAIN_PROJ_NUM}]]></datasetParameterExpression>
                    </datasetParameter>
                    <connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
                </datasetRun>
                <jr:column width="90" uuid="d375f5a3-db9e-450d-8ac2-e1a9a6fc18fc">
                    <jr:columnHeader height="30" rowSpan="1">
                        <staticText>
                            <reportElement uuid="4cd206f2-6591-41a5-969c-9466034aac24" x="0" y="0" width="90" height="30"/>
                            <textElement/>
                            <text><![CDATA[TSDATE]]></text>
                        </staticText>
                    </jr:columnHeader>
                    <jr:detailCell height="20" rowSpan="1">
                        <textField>
                            <reportElement uuid="47c0d3dd-aac2-44ff-a3e5-426cd092fd54" x="0" y="0" width="90" height="20"/>
                            <textElement/>
                            <textFieldExpression><![CDATA[$F{TSDATE}]]></textFieldExpression>
                        </textField>
                    </jr:detailCell>
                </jr:column>
                <jr:column width="90" uuid="587ce56a-9008-43be-b850-dc5397b81c3a">
                    <jr:columnHeader height="30" rowSpan="1">
                        <staticText>
                            <reportElement uuid="73460bc8-c487-4712-8a50-99f624a6bab5" x="0" y="0" width="90" height="30"/>
                            <textElement/>
                            <text><![CDATA[TSCONO]]></text>
                        </staticText>
                    </jr:columnHeader>
                    <jr:detailCell height="20" rowSpan="1">
                        <textField>
                            <reportElement uuid="ce6aaaad-562e-4e8f-9841-d51759e57035" x="0" y="0" width="90" height="20"/>
                            <textElement/>
                            <textFieldExpression><![CDATA[$F{TSCONO}]]></textFieldExpression>
                        </textField>
                    </jr:detailCell>
                </jr:column>
            </jr:table>
        </componentElement>
    </band>
</summary>
于 2013-01-31T16:48:28.640 回答