2012-12-18 35 views
1

我正在使用jasper report 5.0.0并创建一个带有如下所述场景的报告: 在我的ireport中,我需要显示学生姓名,班级,ID,目标, proficiencyForGoal。每个学生都有多个目标,每个目标都有进步。我的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。在单个jasperreport中显示一列中的多条记录

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

欣赏您的快速输入或有关如何达到此要求的想法。

感谢

回答

1

后你已经添加在您的报告中报告,我认为只是放置字段(姓名,班级等)的SQL查询至少应;如果每个学生有多个详细信息,则可以在报告中为每个学生使用子报告。

+0

谢谢你的建议。我使用subdataset和datasetrun列表来显示学生的每个目标标识,而不是subreport。我使用单独的查询来获取subdataset中每个goal_id的熟练程度,如下所示:从prog中选择熟练程度,其中goal_id = 1和student_id = 1。我想知道如何将主报表查询中的字段student_id传递给子数据集作为参数,以便我不需要在子数据集中硬编码student_id。 – JasperNewBie

+0

我不确定有关数据集的信息,但是您可以将主报告中的字段作为参数传递给子报表;有关详细信息和示例,请参阅此链接:http://community.jaspersoft.com/questions/536360/using-field-values-parameter-values-pass-sub-report。 – acostache

0

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

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

然后才能到参数屏幕上,您需要:

右键单击列表 上选择“编辑列表数据源” 在参数标签下点击“添加” 进入顶部拉你将拥有你的数据集参数(student_id)[你只会从你的数据集中获得一个有效参数列表] 在值表达式中你将拥有你的主数据报告$F{student_id}

这将通过从您的主报告中student_id数据到数据集(用于名单的,表的和交叉的)

的那么五言的,你需要添加到您的数据集的where子句

where $P{student_id} = student_id

0

在查询您可以student_id数据

Like: where student_id=$P{p_student_id} 

添加参数化的条件,并保持在总结乐队的一切,如文本字段和静态文本。

0

假设您的查询是由学生命令的一种更简单的方法。 在Ireport添加一个群组(在报告督察右键点击“添加报告组”) 你很可能不需要页眉或页脚 放下所有的领域(名称,职业,ID,goal_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> 
工作
相关问题