jasperreports报表模板的元素

来源:互联网 发布:linux nmon安装 编辑:程序博客网 时间:2024/06/05 20:42

<property>  

用来存储在报表模板中存储信息。可以在代码中通过

JasperReport.getProperty()方法获得属性值。

<property name = "someproperty" value="somevalue" />


<import>

用来导入指定的类或者完整的包

<import value="java.util.HashMap" />


<reportFont>

用来定义一个或多个报表可以显示的字体

<reportFont name="Arial" isDefault="true" fontName="Arial" size="12" 

isBold="true" isItalic="false" />


<parameter>

用来定义报表参数,参数是通过调用JasperReports API接口提供的Map接口提供的。

<parameter name="SomeParameter" class="java.lang.String" />


<queryString>

用来定义SQL 查询语句来从数据库获取数据的。

<queryString>

<![CDATA[SELECT column_name FROM table_name]] >

</queryString>


<field>

用来把数据库或查询语句的数据映射到报表模板中去

<field name="fieldName" class="java.lang.String" />


<variable>

报表表达式,可以赋值给变量,用来简化模板的

<variable name="variableName" class="java.lang.Double" 

calcalation="Sum" >

<variableExpression>

$F{FieldName}

</variableExpression>

</variable>


<group>

用来把一些有同样的特性的分成一组,如同一个国家,城市等。

<group name="GroupName" >

<groupExpression>

<![CDATA[$F{FieldName}]]

</groupExpression>

</group>


<background>

用来定义报表所有页面的背景。

可以用来展示图片或者水印。

<background>
  <band height="745">
    <image scaleImage="Clip" hAlign="Left" vAlign="Bottom"> 
       <reportElement x="0" y="0" width="160" height="745"/> 
       <imageExpression>"image.gif"
       </imageExpression>
    </image>
  </band>
</background>



<title>

这是报表的标题,并且在报表的开头只显示一次

<title>
  <band height="50">
    <staticText>
      <reportElement x="180" y="0" width="200" height="20"/> 
      <text>

        <![CDATA[Title]]> 
      </text> 
    </staticText> 
  </band>
</title>



<pageHeader>

这个元素定义了报表头部,它在报表的每一页都会展示

<pageHeader>
  <band height="20">
    <staticText>
      <reportElement x="180" y="30" width="200" height="20"/> 
      <text>
        <![CDATA[Page Header]]>
      </text>
    </staticText>
  </band>
</pageHeader>



<columnHeader>

如果报表只有一个单行,这个元素会被忽略

<columnHeader>
  <band height="20">
    <staticText>
      <reportElement x="180" y="50" width="200" height="20"/> 
      <text>
       <![CDATA[Column Header]]>
      </text>
    </staticText>
  </band>
</columnHeader>


JRXML模板可以包含一个或者多个<columnHeader>元素,如果存在,columnHeader

元素的数量必须和行的数量相等。


<detail>

这个元素定义了报表中的详细部分。并且在报表的datasource中每一个记录都重复。

<detail>
  <band height="20">
    <textField>
      <reportElement x="10" y="0" width="600" height="20"/> 
      <textFieldExpression class="java.lang.String"> 
        <![CDATA[$F{FieldName}]]> 
      </textFieldExpression>
    </textField>
  </band>
</detail>

这个是报表要展示的主要数据区。


<columnFooter>

如果报表只有一个单行,这个元素会被忽略

<columnFooter>
  <band height="20">
    <staticText>
      <reportElement x="0" y="0" width="200" height="20"/> 
      <text>
        <![CDATA[Column Footer]]>
      </text>
    </staticText>
  </band>
</columnFooter>


<pageFooter>

这个元素定义了一个报表底部,报表中每一页底部都会显示。

<pageFooter>
  <band height="20">
    <staticText>
      <reportElement  x="0" y="5" width="200" height="20"/> 
      <text>
        <![CDATA[Page Footer]]>
      </text>
    </staticText>
  </band>
</pageFooter>


<lastPageFooter>

报表最后一页的底部展示的是lastPageFooter中定义的数据,而不是pageFooter元素中定义的数据。

<lastPageFooter>
  <band height="20"> 
    <staticText>
      <reportElement  x="0" y="5" 
        width="200" height="20"/> 
      <text>
        <![CDATA[Last Page Footer]]> 
      </text>
    </staticText>
  </band>
</lastPageFooter>


<summary>

这个在报表的尾部只展示一次。

<summary>
  <band height="20">
    <staticText>
      <reportElement  x="0" y="5" width="200" height="20"/> 
      <text>
        <![CDATA[Summary]]>
      </text>
    </staticText>
  </band>
</summary>




就像<detail>元素一样,每一个前面讨论的元素都会包含一个<band>子元素。

下面是各元素占用的区域预览图。以供设计时参考。





<staticText>

定义不依赖于任何datasource,变量,参数,或者报表表达式的文本。


<reportElement>

定义了元素的位置和宽度。


<text>定义了报表展示的实际文本


原创粉丝点击