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>
<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 name="code"><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>
<variable name="fixed_wing_engine_cnt" name="code"><textFieldExpression> <![CDATA["Total Fixed Wing Aircraft Models: " +$V{fixed_wing_engine_cnt}]]></textFieldExpression>
<variable name="aircraft_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}-->
<textField isStretchWithOverflow="true"> <reportElement x="0" y="0" width="100" height="24"/> <textFieldExpression name="code"><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>