1

我正在使用iReport 5.1.0工具进行报表设计。

我当前的报告输出就像,

------------------------------------------------------------
| STUDENT_ID | SUBJECT_NAME | SUBJECT_MARK | STUDENT_NAME |
------------------------------------------------------------
|     1      |   Maths      |      25      |     John     |
------------------------------------------------------------
|     1      |   English    |      35      |     John     |
------------------------------------------------------------
|     2      |   Maths      |      30      |     James    |
------------------------------------------------------------
|     2      |   English    |      23      |     James    |
------------------------------------------------------------

但我需要类似的东西,

------------------------------------------------------------
| STUDENT_ID | SUBJECT_NAME | SUBJECT_MARK | STUDENT_NAME |
------------------------------------------------------------
|     1      |   Maths      |      25      |     John     |
             -------------------------------
|            |   English    |      35      |              |
------------------------------------------------------------
|     2      |   Maths      |      30      |     James    |
             -------------------------------
|            |   English    |      23      |              |
------------------------------------------------------------

这是我的.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="testStudent" language="groovy" pageWidth="792" pageHeight="612" orientation="Landscape" columnWidth="752" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="31359f99-5457-4827-9bdb-e1160fe03bdc">
<property name="ireport.zoom" value="1.0"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="0"/>
<field name="studentId" class="java.lang.String"/>
<field name="studentName" class="java.lang.String"/>
<field name="subjectName" class="java.lang.String"/>
<field name="subjectMark" class="java.lang.String"/>
<background>
    <band splitType="Stretch"/>
</background>
<title>
    <band height="31" splitType="Stretch">
        <staticText>
            <reportElement uuid="c04d7e4f-68ce-4519-a96d-8c4ba4dd4bba" x="0" y="0" width="205" height="31"/>
            <textElement>
                <font size="20" isBold="true"/>
            </textElement>
            <text><![CDATA[Test Students]]></text>
        </staticText>
    </band>
</title>
<pageHeader>
    <band height="3" splitType="Stretch"/>
</pageHeader>
<columnHeader>
    <band height="23" splitType="Stretch">
        <staticText>
            <reportElement uuid="04cf5bc0-ff69-47e3-af7c-b2702b1d5e90" x="0" y="2" width="100" height="20"/>
            <box>
                <pen lineWidth="1.0"/>
                <topPen lineWidth="1.0"/>
                <leftPen lineWidth="1.0"/>
                <bottomPen lineWidth="1.0"/>
                <rightPen lineWidth="1.0"/>
            </box>
            <textElement/>
            <text><![CDATA[STUDENT_ID]]></text>
        </staticText>
        <staticText>
            <reportElement uuid="b3c3a500-fb03-459f-b600-8ef738b3a795" x="300" y="2" width="100" height="20"/>
            <box>
                <pen lineWidth="1.0"/>
                <topPen lineWidth="1.0"/>
                <leftPen lineWidth="1.0"/>
                <bottomPen lineWidth="1.0"/>
                <rightPen lineWidth="1.0"/>
            </box>
            <textElement/>
            <text><![CDATA[STUDENT_NAME]]></text>
        </staticText>
        <staticText>
            <reportElement uuid="04c057c8-e4cb-4ad9-876f-40ec3af568c4" x="100" y="2" width="100" height="20"/>
            <box>
                <pen lineWidth="1.0"/>
                <topPen lineWidth="1.0"/>
                <leftPen lineWidth="1.0"/>
                <bottomPen lineWidth="1.0"/>
                <rightPen lineWidth="1.0"/>
            </box>
            <textElement/>
            <text><![CDATA[SUBJECT_NAME]]></text>
        </staticText>
        <staticText>
            <reportElement uuid="3f78e926-ed9e-4306-b0d7-cc03243bef4b" x="200" y="2" width="100" height="20"/>
            <box>
                <pen lineWidth="1.0"/>
                <topPen lineWidth="1.0"/>
                <leftPen lineWidth="1.0"/>
                <bottomPen lineWidth="1.0"/>
                <rightPen lineWidth="1.0"/>
            </box>
            <textElement/>
            <text><![CDATA[SUBJECT_MARK]]></text>
        </staticText>
    </band>
</columnHeader>
<detail>
    <band height="21" splitType="Stretch">
        <textField>
            <reportElement uuid="e15a2c2c-76f7-40bb-bb88-dde1f89ff2d5" x="0" y="0" width="100" height="20"/>
            <box>
                <pen lineWidth="1.0"/>
                <topPen lineWidth="1.0"/>
                <leftPen lineWidth="1.0"/>
                <bottomPen lineWidth="1.0"/>
                <rightPen lineWidth="1.0"/>
            </box>
            <textElement/>
            <textFieldExpression><![CDATA[$F{studentId}]]></textFieldExpression>
        </textField>
        <textField>
            <reportElement uuid="6da8fc6d-918b-4984-b374-57ab8669de80" x="300" y="0" width="100" height="20"/>
            <box>
                <pen lineWidth="1.0"/>
                <topPen lineWidth="1.0"/>
                <leftPen lineWidth="1.0"/>
                <bottomPen lineWidth="1.0"/>
                <rightPen lineWidth="1.0"/>
            </box>
            <textElement/>
            <textFieldExpression><![CDATA[$F{studentName}]]></textFieldExpression>
        </textField>
        <textField>
            <reportElement uuid="827a067f-e2a2-4a2e-a8f0-bf765e6ed241" x="100" y="0" width="100" height="20"/>
            <box>
                <pen lineWidth="1.0"/>
                <topPen lineWidth="1.0"/>
                <leftPen lineWidth="1.0"/>
                <bottomPen lineWidth="1.0"/>
                <rightPen lineWidth="1.0"/>
            </box>
            <textElement/>
            <textFieldExpression><![CDATA[$F{subjectName}]]></textFieldExpression>
        </textField>
        <textField>
            <reportElement uuid="23463a34-0af0-4897-8745-6fe477919a83" x="200" y="0" width="100" height="20"/>
            <box>
                <pen lineWidth="1.0"/>
                <topPen lineWidth="1.0"/>
                <leftPen lineWidth="1.0"/>
                <bottomPen lineWidth="1.0"/>
                <rightPen lineWidth="1.0"/>
            </box>
            <textElement/>
            <textFieldExpression><![CDATA[$F{subjectMark}]]></textFieldExpression>
        </textField>
    </band>
</detail>
<columnFooter>
    <band height="4" splitType="Stretch"/>
</columnFooter>
<pageFooter>
    <band height="5" splitType="Stretch"/>
</pageFooter>
<summary>
    <band height="4" splitType="Stretch"/>
</summary></jasperReport>

有谁能够帮我?提前致谢。

4

1 回答 1

0

在此处输入图像描述 首先,您应该创建一个数据组。

1.go to report inspector
2.right click on the jrxml name at the top of the report inpector 
3.select add report group. 
4.input the group name 
5. select the object, in your case student_id from the 'group by the following report   object'
6. click next 
7. Chose add report group header or footer or both if you want to. (in your case i think you should not add report group header or footer)

您的报告组将被添加。尝试重新生成报告。您还应该取消选中“打印重复值”

于 2013-10-04T10:37:35.873 回答