`

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 Expressions可能会用到两次以上,就可以考虑
<variable name="fixed_wing_engine_cnt" class="java.lang.Integer">
 <variableExpression>
  <![CDATA[new Integer($F{fixed_wing_single_engine_cnt}.intValue() +
    $F{fixed_wing_multiple_engine_cnt}.intValue())]]>
 </variableExpression>
</variable>

这样,只要在里面调用
<textFieldExpression>
  <![CDATA["Total Fixed Wing Aircraft Models: " +
$V{fixed_wing_engine_cnt}]]>
</textFieldExpression>


Report Variables还可以做复杂的运算,从他的属性里面就看的出来
name(Variables名字)
class(类形,如java.lang.Integer)
calculation(计算方式,Average,Count,First,Highest,Lowest,Nothing,Sum,System,Variance)

resetType(Column,Group,None,Page,Report)重设的类型,一般用在Group一组
resetGroup(当重设的类型为Group的时候,就选择组名)

如下例子
<variable name="aircraft_count" class="java.lang.Integer"
calculation="Count" resetType="Group"
resetGroup="StateGroup">
 <variableExpression>
   <![CDATA[$F{aircraft_serial}]]>
 </variableExpression>
 <initialValueExpression>
  <![CDATA[new java.lang.Integer(0)]]>
 </initialValueExpression>
</variable>
<group name="StateGroup">
  ......
</group>
<!--使用的时候就用$V{aircraft_count}-->

7.Built-In Report Variables(默认,初始都有的变量)
$V{PAGE_NUMBER}(当前页),$V{COLUMN_NUMBER}(当前列),$V{REPORT_COUNT}(一共有多少条记录),$V{PAGE_COUNT}(一共有多少页),$V{COLUMN_COUNT}(一共有多少列)

8.对文字过多的适当调解
用这个,就可以适当调解了,设为TRUE
<textField isStretchWithOverflow="true">
    <reportElement x="0" y="0" width="100" height="24"/>
    <textFieldExpression class="java.lang.String">
    <![CDATA[$F{lots_of_data}]]>
    </textFieldExpression>
</textField>


9.<reportElement>设置位置

这个有很多属性,最常用的还是这样用,最好还是用FRAME布局更好一些
<reportElement x="20" y="0" width="200" height="20"/>

隐藏重复的值
<!--是否输出重复的值-->
<reportElement x="56" y="0" height="20" width="164"
isPrintRepeatedValues="false"/>
 <textFieldExpression>
   <![CDATA["Model: " + $F{model}]]>
 </textFieldExpression>
</textField>

分享到:
评论
6 楼 hpgyy 2009-08-25  
<div class="quote_title">langhua9527 写道</div>
<div class="quote_div">
<br>isTitleNewPage表示每一页都是否显示标题,默认为false <br><br>isSummaryNewPage每一页都是否显示摘要,默认为false <br><br>
</div>
<p> </p>
<p><span style="background-color: #fafafa;">这儿有误,应为:</span></p>
<p><span style="background-color: #fafafa;">isTitleNewPage:表示是否单独一页显示标题,默认为false,为true则报表第一页仅显示为标题 </span></p>
<p><span style="background-color: #fafafa;">isSummaryNewPage 表示是否单独一页显示汇总,默认为false,为true则表示汇总在报表最后另起新的一页显示</span></p>
5 楼 longlongriver 2009-06-23  
我直接用的iReport,直接编辑jrxml文件太麻烦了,也不只管,对复杂报表来说这几乎是不可能的任务,首先就个位置点就能把人整疯!
4 楼 dellsoft 2009-06-19  
具体参看
http://dynamicjasper.sourceforge.net/
3 楼 langhua9527 2009-06-06  
其实我都是用iReport设计的。
2 楼 langhua9527 2009-06-06  
dellsoft 写道
建议直接用djasper,对jasperreport的 封装。用代码就可以搞定jasperreport设计。

djasper是啥子东西,介绍一下啥
1 楼 dellsoft 2009-06-06  
建议直接用djasper,对jasperreport的 封装。用代码就可以搞定jasperreport设计。

相关推荐

Global site tag (gtag.js) - Google Analytics