JasperReport学习笔记6-JRXML的标签

[size=xx-large][color=blue]1.<jasperReport>根元素包括很多属性[/color][/size]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

[size=xx-large][color=blue]2.文本的属性控制[/color][/size]
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>

[size=xx-large][color=blue]3.背景控制(background)[/color][/size]
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>


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

[size=xx-large][color=blue]5.Report Expressions[/color][/size]例子如下

<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>


[size=xx-large][color=blue]6.Report Variables[/color][/size]
因为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}-->

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

[size=xx-large][color=blue]8.对文字过多的适当调解[/color][/size]
用这个,就可以适当调解了,设为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>

[size=xx-large][color=blue]
9.<reportElement>设置位置[/color][/size]
这个有很多属性,最常用的还是这样用,最好还是用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>
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值