在单个jasperreport中显示一列的多个记录

时间:2012-12-18 12:55:27

标签: jasper-reports

我正在使用jasper report 5.0.0并使用如下所述的方案创建报告: 在我的ireport中,我需要显示学生的姓名,班级,身份,目标,熟练度。每个学生都有多个目标,每个目标都有进步。我的sql查询如下: 从2或3个表中选择stud.name,stud.class,stud.id,prog.goal_id,prog.proficiency,这些表由prog.goal_id连接和分组。此查询为每个学生提供多行。并且ireport每行创建多个PDF(使用PDF预览版)。 但我希望在单个PDF 中显示所有目标和目标熟练程度以及学生详细信息,如姓名,班级,ID。那就是我希望每个学生都有一份PDF,其中包含所有细节。所以,如果有500名学生,那么500 pdf。

假设每个学生有10个目标,那么我现在得到的是一个学生的10个PDF,其名称,班级,ID重复,500个学生我得到500 * 10 = 5000 pdfs我不想要。

感谢您对如何达到此要求的快速输入或想法。

由于

4 个答案:

答案 0 :(得分:1)

在您的报告中添加了sql查询后,我认为只需在报告中放置字段(名称,类等);此外,如果每位学生有多个详细信息,您可以在报告中为每个学生使用子报告。

答案 1 :(得分:0)

不知道如何将其添加为评论,所以我把它放在这里。

要将值传递给数据集,它的工作方式很像子报表,但参数选项不在Ireport的属性部分。
就像在子报表中一样,您首先需要将参数添加到数据集(student_id)

然后进入参数屏幕,您需要:

右键单击列表 选择“编辑列表数据源” 在参数选项卡下单击“添加” 在顶部拉你将有你的数据集参数(student_id)[你只会从你的数据集中获得有效参数的列表] 在值表达式中,您将获得主报告$F{student_id}

这会将student_id从主报告传递到数据集(用于列表,表格和交叉表)

然后是cource,你需要添加到数据集的where子句

where $P{student_id} = student_id

答案 2 :(得分:0)

在查询中,您可以为student_id添加参数化条件

Like:  where student_id=$P{p_student_id}

并将文本字段和静态文本等所有内容保留在摘要区域中。

答案 3 :(得分:0)

一种更简单的方法,假设您的查询是由学生订购的。 在Ireport中添加一个组(在报告检查器中右键单击根点击“添加报告组”) 你最有可能不需要页眉或页脚 放下你所有的领域(名字,职业,id,goal_id,熟练程度)   您可能需要在名称,类,ID上单击“打印重复值”属性 选择您的组(在报告检查器中)   选择“在新页面上开始”(您可能还想重置页面#并重新打印标题)   也“团结一致”

这是一个示例,您需要将查询放入其中以便在所有

中工作
<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="report9" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="5ac8f93f-0f1f-4f1c-8c7c-41a15b76ef65">
<?xml version="1.0" encoding="UTF-8"?>
    <property name="ireport.zoom" value="1.0"/>
    <property name="ireport.x" value="0"/>
    <property name="ireport.y" value="0"/>
    <queryString>
        <![CDATA[select sysdate from dual ]]>
    </queryString>
    <field name="name" class="java.lang.String"/>
    <field name="class" class="java.lang.String"/>
    <field name="id" class="java.lang.String"/>
    <field name="goal_id" class="java.lang.String"/>
    <field name="proficiency" class="java.lang.String"/>
    <group name="Student Name" isStartNewPage="true" isResetPageNumber="true" isReprintHeaderOnEachPage="true" keepTogether="true">
        <groupExpression><![CDATA[$F{name}]]></groupExpression>
    </group>
    <background>
        <band splitType="Stretch"/>
    </background>
    <title>
        <band height="79" splitType="Stretch"/>
    </title>
    <pageHeader>
        <band height="35" splitType="Stretch"/>
    </pageHeader>
    <columnHeader>
        <band height="20" splitType="Stretch">
            <staticText>
                <reportElement uuid="b78d9294-5efc-4d3a-a08b-749493ecf242" x="0" y="0" width="111" height="20"/>
                <textElement/>
                <text><![CDATA[name]]></text>
            </staticText>
            <staticText>
                <reportElement uuid="8eeacd33-15c4-416e-981e-f8aac2586443" x="111" y="0" width="111" height="20"/>
                <textElement/>
                <text><![CDATA[class]]></text>
            </staticText>
            <staticText>
                <reportElement uuid="dc878516-ecc7-405d-a288-ead78229e564" x="222" y="0" width="111" height="20"/>
                <textElement/>
                <text><![CDATA[id]]></text>
            </staticText>
            <staticText>
                <reportElement uuid="0eb5c805-4358-4d85-b567-d513a318a54d" x="333" y="0" width="111" height="20"/>
                <textElement/>
                <text><![CDATA[goal_id]]></text>
            </staticText>
            <staticText>
                <reportElement uuid="b9675b06-87ac-4441-a207-0cbd58dbf925" x="444" y="0" width="111" height="20"/>
                <textElement/>
                <text><![CDATA[proficiency]]></text>
            </staticText>
        </band>
    </columnHeader>
    <detail>
        <band height="20" splitType="Stretch">
            <textField>
                <reportElement uuid="b284aaa5-475e-4b54-a1bd-ce4772cf79a2" isPrintRepeatedValues="false" x="0" y="0" width="111" height="20"/>
                <textElement/>
                <textFieldExpression><![CDATA[$F{name}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement uuid="80f38abc-1cb3-41c0-a9c6-2473e84a8c6d" isPrintRepeatedValues="false" x="111" y="0" width="111" height="20"/>
                <textElement/>
                <textFieldExpression><![CDATA[$F{class}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement uuid="30a371f8-4d08-4125-8e85-497b2697e9d3" x="222" y="0" width="111" height="20"/>
                <textElement/>
                <textFieldExpression><![CDATA[$F{id}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement uuid="53757283-0c03-4248-9848-1eba9ee168b7" x="333" y="0" width="111" height="20"/>
                <textElement/>
                <textFieldExpression><![CDATA[$F{goal_id}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement uuid="3d2bbbc0-0fe1-4442-809f-acee606db5ac" x="444" y="0" width="111" height="20"/>
                <textElement/>
                <textFieldExpression><![CDATA[$F{proficiency}]]></textFieldExpression>
            </textField>
        </band>
    </detail>
    <columnFooter>
        <band height="45" splitType="Stretch"/>
    </columnFooter>
    <pageFooter>
        <band height="54" splitType="Stretch"/>
    </pageFooter>
    <summary>
        <band height="42" splitType="Stretch"/>
    </summary>
</jasperReport>
相关问题