如何在多个表中使用相同的REPORT_COUNT递增呢?

How to use the same REPORT_COUNT in multiple tables incrementing it?

我正在使用 iReport 5.6 为我的 JavaApp 生成报告,我有三个数据集,如下所示:

数据集1查询

SELECT * FROM players s WHERE s.role = 1

数据集2查询

SELECT * FROM players s WHERE s.role = 2

数据集3查询

SELECT * FROM players s WHERE s.role = 3

然后我在我放置的位置创建了 3 个细节带:

我不能做的是使用 $V{REPORT_COUNT} jasper 变量为三个 table 添加一个计数列,它不会刷新计数,因为 我想要这个计数以继续递增。

为此,您可以使用从 datasetRun (table) 指定 returnValue 的可能性,然后将其作为 datasetParameter 传递给下一个 datasetRun (table)

在示例中,我们将作为 returnValue$V{REPORT_COUNT}(table 的)传递给主报告 $V{currentRecordCnt} 中的变量,currentRecordCnt 我们然后将传递到下一个 datasetRun (table 2) 并使用它来增加 2 dataset

中的变量
<variable name="accRecordCnt" class="java.lang.Integer">
    <variableExpression><![CDATA[$P{currentRecordCnt}+$V{REPORT_COUNT}]]></variableExpression>
</variable>

然后我们将 accRecordCnt 传回主报告的 currentRecordCnt 并为 table 重复相同的操作 3.

完整的 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="AccuSum" pageWidth="595" pageHeight="842" whenNoDataType="AllSectionsNoDetail" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="85a44d77-bc70-4059-a88a-60aca0ef6bf0">
    <property name="com.jaspersoft.studio.data.defaultdataadapter" value="One Empty Record"/>
    <subDataset name="Dataset1" uuid="5a00c263-2028-4446-948e-d614136ec5d7">
        <queryString>
            <![CDATA[]]>
        </queryString>
    </subDataset>
    <subDataset name="Dataset2" uuid="3ff8e779-2e60-403c-81f8-1d20fd04fc78">
        <parameter name="currentRecordCnt" class="java.lang.Integer"/>
        <queryString>
            <![CDATA[]]>
        </queryString>
        <variable name="accRecordCnt" class="java.lang.Integer">
            <variableExpression><![CDATA[$P{currentRecordCnt}+$V{REPORT_COUNT}]]></variableExpression>
        </variable>
    </subDataset>
    <subDataset name="Dataset3" uuid="3ff8e779-2e60-403c-81f8-1d20fd04fc78">
        <parameter name="currentRecordCnt" class="java.lang.Integer"/>
        <queryString>
            <![CDATA[]]>
        </queryString>
        <variable name="accRecordCnt" class="java.lang.Integer">
            <variableExpression><![CDATA[$P{currentRecordCnt}+$V{REPORT_COUNT}]]></variableExpression>
        </variable>
    </subDataset>
    <queryString>
        <![CDATA[]]>
    </queryString>
    <variable name="currentRecordCnt" class="java.lang.Integer"/>
    <detail>
        <band height="54" splitType="Stretch">
            <componentElement>
                <reportElement x="0" y="10" width="540" height="30" uuid="c46d16ff-7b32-4481-8d89-0435f34f7b32">
                    <property name="com.jaspersoft.studio.layout" value="com.jaspersoft.studio.editor.layout.VerticalRowLayout"/>
                </reportElement>
                <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="Dataset1" uuid="6b893feb-3e07-4393-ae4d-30b64e3dbaf5">
                        <dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.JREmptyDataSource(5)]]></dataSourceExpression>
                        <returnValue fromVariable="REPORT_COUNT" toVariable="currentRecordCnt"/>
                    </datasetRun>
                    <jr:column width="160" uuid="3b6f8589-0c6d-4709-a8cd-6cf642fd4ec9">
                        <jr:detailCell height="30">
                            <textField>
                                <reportElement x="0" y="0" width="160" height="30" uuid="a04fcd2b-e179-4fdb-8eac-31da14721c9a"/>
                                <textFieldExpression><![CDATA[$V{REPORT_COUNT}]]></textFieldExpression>
                            </textField>
                        </jr:detailCell>
                    </jr:column>
                </jr:table>
            </componentElement>
        </band>
        <band height="50">
            <componentElement>
                <reportElement x="0" y="10" width="540" height="30" uuid="6866e777-15b8-49a7-b00f-3ce3593c16c0">
                    <property name="com.jaspersoft.studio.layout" value="com.jaspersoft.studio.editor.layout.VerticalRowLayout"/>
                </reportElement>
                <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="Dataset2" uuid="f71b2649-27c0-4a30-bb68-8bc7c8a26100">
                        <datasetParameter name="currentRecordCnt">
                            <datasetParameterExpression><![CDATA[$V{currentRecordCnt}]]></datasetParameterExpression>
                        </datasetParameter>
                        <dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.JREmptyDataSource(5)]]></dataSourceExpression>
                        <returnValue fromVariable="accRecordCnt" toVariable="currentRecordCnt"/>
                    </datasetRun>
                    <jr:column width="160" uuid="6e116b9f-cf9f-4a27-9e9a-892263482caf">
                        <property name="com.jaspersoft.studio.components.table.model.column.name" value="Column1"/>
                        <jr:detailCell height="30">
                            <textField>
                                <reportElement x="0" y="0" width="160" height="30" uuid="8cb085f1-5155-4b17-9304-c3bb616ac965"/>
                                <textFieldExpression><![CDATA[$V{accRecordCnt}]]></textFieldExpression>
                            </textField>
                        </jr:detailCell>
                    </jr:column>
                </jr:table>
            </componentElement>
        </band>
        <band height="50">
            <componentElement>
                <reportElement x="0" y="10" width="540" height="30" uuid="338527a7-5c7e-419d-ac85-658ac2d30655">
                    <property name="com.jaspersoft.studio.layout" value="com.jaspersoft.studio.editor.layout.VerticalRowLayout"/>
                </reportElement>
                <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="Dataset3" uuid="8c00ef2e-d328-42a8-8ba5-12bfde8225c0">
                        <datasetParameter name="currentRecordCnt">
                            <datasetParameterExpression><![CDATA[$V{currentRecordCnt}]]></datasetParameterExpression>
                        </datasetParameter>
                        <dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.JREmptyDataSource(5)]]></dataSourceExpression>
                    </datasetRun>
                    <jr:column width="160" uuid="7e28ae8d-b64b-42fa-a5eb-4213198d1341">
                        <property name="com.jaspersoft.studio.components.table.model.column.name" value="Column1"/>
                        <jr:detailCell height="30">
                            <textField>
                                <reportElement x="0" y="0" width="160" height="30" uuid="05900214-f740-4742-bae3-f4a97aed073e"/>
                                <textFieldExpression><![CDATA[$V{accRecordCnt}]]></textFieldExpression>
                            </textField>
                        </jr:detailCell>
                    </jr:column>
                </jr:table>
            </componentElement>
        </band>
    </detail>
</jasperReport>

输出(有 1 条空记录)