日期:2014-05-17  浏览次数:20885 次

JasperReport学习笔记6-JRXML的标签
1.<jasperReport>根元素包括很多属性pageWidth,pageHeight,leftMargin,rightMargin,topMargin,bottomMargin,orientation,whenNoDataType,isTitleNewPage,isSummaryNewPage

orientation表示是横着放,还是竖着放,默认是Portrait(横),也可以选Landscape(竖)

whenNoDataType表示页面没有信息的时候怎么办,默认是no pages,如果你想没有数据的时候也显示,就用AllSectionsNoDetail

isTitleNewPage表示每一页都是否显示标题,默认为false

isSummaryNewPage每一页都是否显示摘要,默认为false

pageWidth默认595,pageHeight默认842,leftMargin和rightMargin默认20,topMargin,bottomMargin都默认30

2.文本的属性控制
jasperreport有多种方式控制文本的属性
第一种,用<style>element控制,他的属性有
forecolor(前景色,就是文本)
backcolor(背景色)
hAlign(水平位置Center, Justified, Left, Right)
vAlign(垂直位置Bottom, Middle, Top)
border(边框1Point, 2Point, 4Point, Dotted, None, Thin)
borderColor(边框颜色)
padding(旁白,单位象素)
fontName(字体)
fontSize(字体大小)
isBold,isItalic,IsUnderline,isStrikeThrough(粗体,斜体,下画线,..)
lineSpacing(1_1_2, Double, Single行间距)
rotation(旋转,Left, None, Right,转的是90度)
isStyledText(指示这个Element是否用Style,true,false)
isDefault(说明这个样式是否默认样式)
style(style支持继承)

第二种方法:在textElement里面控制属性,标签和上面一样
只是设置文件属性的位置

textAlignment(Center, Justified, Left, Right)
verticalAlignment(Bottom, Middle, Top)
有区别,style用的是hAlign,vAlign
<staticText>
 <reportElement x="0" y="0" width="555" height="30"/>
 <textElement lineSpacing="Double" textAlignment="center"
verticalAlignment="Middle"/>
 <text>
   <![CDATA[This text is not really important.]]>
 </text>
</staticText>

The <textElement> element is a sub-element of both <staticText> and <textField>

3.背景控制(background)
mode="Transparent"必须加上这个,背影用
<style name="centeredText" hAlign="Center" vAlign="Middle"/>
<style name="boldCentered" style="centeredText" isBold="true"/>
<style name="backgroundStyle" style="boldCentered"
fontName="Helvetica" pdfFontName="Helvetica-Bold"
forecolor="lightGray" fontSize="90"/>
<background>
  <band height="782">
    <staticText>
      <reportElement x="0" y="0" width="555" height="782"
style="backgroundStyle" mode="Transparent"/>
      <textElement rotation="None"/>
    <text>
    <![CDATA[SAMPLE]]>
    </text>
    </staticText>
  </band>
</background>


对背影图片的控制
<background>
 <band height="391">
  <image>
  <reportElement x="65" y="0" width="391" height="391"/>
   <imageExpression class="java.lang.String">
    <![CDATA["reports/company_logo.gif"]]>
   </imageExpression>
  </image>
 </band>
</background>


4.分组(group)
isStartNewPage,isStartNewColumn,isReprintHeaderOnEachPage,isResetPageNumber
这四个都是默认的false如果需要就设置成true
group必要有的子标签是groupExpression,可选择性的子标签是groupHeader,groupFooter

5.Report Expressions例子如下
<textField>
 <reportElement x="20" y="80" height="20" width="500"/>
 <textFieldExpression>
   <![CDATA["Total Aircraft Models Reported: " +
  ($F{fixed_wing_single_engine_cnt}.intValue() +
  $F{fixed_wing_multiple_engine_cnt}.intValue() +
  $F{rotorcraft_cnt}.intValue())]]>
 </textFieldExpression>
</textField>


6.Report Variables
因为Report Expr