原文源於:http://langhua9527.iteye.com/blog/402317
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 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>
6.Report Variables
因為Report Expressions可能會用到兩次以上,就可以考慮
<variable name="fixed_wing_engine_cnt" name="code"><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" 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 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>
1 樓 dellsoft 2009-06-06 建議直接用djasper,對jasperreport的 封裝。用代碼就可以搞定jasperreport設計。 2 樓 langhua9527 2009-06-06 dellsoft 寫道建議直接用djasper,對jasperreport的 封裝。用代碼就可以搞定jasperreport設計。
djasper是啥子東西,介紹一下啥
3 樓 langhua9527 2009-06-06 其實我都是用iReport設計的。 4 樓 dellsoft 2009-06-19 具體參看
http://dynamicjasper.sourceforge.net/ 5 樓 longlongriver 2009-06-23 我直接用的iReport,直接編輯jrxml文件太麻煩了,也不只管,對復雜報表來說這幾乎是不可能的任務,首先就個位置點就能把人整瘋! 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="">這兒有誤,應為:</span></p>
<p><span style="">isTitleNewPage:表示是否單獨一頁顯示標題,默認為false,為true則報表第一頁僅顯示為標題 </span></p>
<p><span style="">isSummaryNewPage 表示是否單獨一頁顯示匯總,默認為false,為true則表示匯總在報表最后另起新的一頁顯示</span></p>