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 
Xml代碼  收藏代碼
  1. <staticText>  
  2.  <reportElement x="0" y="0" width="555" height="30"/>  
  3.  <textElement lineSpacing="Double" textAlignment="center"  
  4. verticalAlignment="Middle"/>  
  5.  <text>  
  6.    <![CDATA[This text is not really important.]]>  
  7.  </text>  
  8. </staticText>  

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

3.背景控制(background) 
mode="Transparent"必須加上這個,背影用 
Xml代碼  收藏代碼
  1. <style name="centeredText" hAlign="Center" vAlign="Middle"/>  
  2. <style name="boldCentered" style="centeredText" isBold="true"/>  
  3. <style name="backgroundStyle" style="boldCentered"  
  4. fontName="Helvetica" pdfFontName="Helvetica-Bold"  
  5. forecolor="lightGray" fontSize="90"/>  
  6. <background>  
  7.   <band height="782">  
  8.     <staticText>  
  9.       <reportElement x="0" y="0" width="555" height="782"  
  10. style="backgroundStyle" mode="Transparent"/>  
  11.       <textElement rotation="None"/>  
  12.     <text>  
  13.     <![CDATA[SAMPLE]]>  
  14.     </text>  
  15.     </staticText>  
  16.   </band>  
  17. </background>  


對背影圖片的控制 
Xml代碼  收藏代碼
  1. <background>  
  2.  <band height="391">  
  3.   <image>  
  4.   <reportElement x="65" y="0" width="391" height="391"/>  
  5.    <imageExpression class="java.lang.String">  
  6.     <![CDATA["reports/company_logo.gif"]]>  
  7.    </imageExpression>  
  8.   </image>  
  9.  </band>  
  10. </background>  


4.分組(group) 
isStartNewPage,isStartNewColumn,isReprintHeaderOnEachPage,isResetPageNumber 
這四個都是默認的false如果需要就設置成true 
group必要有的子標籤是groupExpression,可選擇性的子標籤是groupHeader,groupFooter 

5.Report Expressions例子如下 
Xml代碼  收藏代碼
  1. <textField>  
  2.  <reportElement x="20" y="80" height="20" width="500"/>  
  3.  <textFieldExpression>  
  4.    <![CDATA["Total Aircraft Models Reported: " + 
  5.   ($F{fixed_wing_single_engine_cnt}.intValue() + 
  6.   $F{fixed_wing_multiple_engine_cnt}.intValue() + 
  7.   $F{rotorcraft_cnt}.intValue())]]>  
  8.  </textFieldExpression>  
  9. </textField>  


6.Report Variables 
因爲Report Expressions可能會用到兩次以上,就可以考慮 
Xml代碼  收藏代碼
  1. <variable name="fixed_wing_engine_cnt" class="java.lang.Integer">  
  2.  <variableExpression>  
  3.   <![CDATA[new Integer($F{fixed_wing_single_engine_cnt}.intValue() + 
  4.     $F{fixed_wing_multiple_engine_cnt}.intValue())]]>  
  5.  </variableExpression>  
  6. </variable>  

這樣,只要在裏面調用 
Xml代碼  收藏代碼
  1. <textFieldExpression>  
  2.   <![CDATA["Total Fixed Wing Aircraft Models: " + 
  3. $V{fixed_wing_engine_cnt}]]>  
  4. </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的時候,就選擇組名) 

如下例子 
Xml代碼  收藏代碼
  1. <variable name="aircraft_count" class="java.lang.Integer"  
  2. calculation="Count" resetType="Group"  
  3. resetGroup="StateGroup">  
  4.  <variableExpression>  
  5.    <![CDATA[$F{aircraft_serial}]]>  
  6.  </variableExpression>  
  7.  <initialValueExpression>  
  8.   <![CDATA[new java.lang.Integer(0)]]>  
  9.  </initialValueExpression>  
  10. </variable>  
  11. <group name="StateGroup">  
  12.   ......  
  13. </group>  
  14. <!--使用的時候就用$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 
Xml代碼  收藏代碼
  1. <textField isStretchWithOverflow="true">  
  2.     <reportElement x="0" y="0" width="100" height="24"/>  
  3.     <textFieldExpression class="java.lang.String">  
  4.     <![CDATA[$F{lots_of_data}]]>  
  5.     </textFieldExpression>  
  6. </textField>  


9.<reportElement>設置位置
 
這個有很多屬性,最常用的還是這樣用,最好還是用FRAME佈局更好一些 
Xml代碼  收藏代碼
  1. <reportElement x="20" y="0" width="200" height="20"/>  

隱藏重複的值 
Xml代碼  收藏代碼
  1. <!--是否輸出重複的值-->  
  2. <reportElement x="56" y="0" height="20" width="164"  
  3. isPrintRepeatedValues="false"/>  
  4.  <textFieldExpression>  
  5.    <![CDATA["Model: " + $F{model}]]>  
  6.  </textFieldExpression>  
  7. </textField>  



轉載自:http://langhua9527.iteye.com/blog/402317

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章