JasperReports最終用戶手冊中文版第四節(jié)報表設計_第1頁
JasperReports最終用戶手冊中文版第四節(jié)報表設計_第2頁
JasperReports最終用戶手冊中文版第四節(jié)報表設計_第3頁
JasperReports最終用戶手冊中文版第四節(jié)報表設計_第4頁
JasperReports最終用戶手冊中文版第四節(jié)報表設計_第5頁
已閱讀5頁,還剩2頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領

文檔簡介

1、第四章 報表設計 “報表設計(report design)”是一個模板,JasperReports 引擎會用它來傳遞動態(tài)內容到打印機,屏幕或者是Web頁面。存儲于數據庫中的數據會根據報表的實際設計來填充整個報表,打印到頁面導向的文檔。The report design represents a template that will be used by the JasperReports engine to deliver dynamic content to the printer, to the screen or to the Web. Data stored in the databa

2、se is organized during the report filling process according to this report design to obtain ready to print, page oriented documents.通常,一個“報表設計”包含了關于數據填充后所形成的報表(documents)的結構和所有的其他方面的信息。這些信息包括將要輸出到報表上的各種文本,圖像元素的位置,內容,以及要進行的數據計算,自定義計算,分組,操作等信息。Generally speaking, a report design contains all the infor

3、mation concerning the structure and the aspect of the documents that will be generated when the data will be provided. This information concerns the position and the content of various text or graphic elements that will appear on the document, their appearance, the custom calculations, data grouping

4、 and data manipulation that should be performed when generating the documents, etc.一般,“報表設計(report design)”用一種特殊的結構定義在Xml文檔中(我們會在稍后詳細分析),在被填充數據前,這一過程屬于JasperReports 報表的編輯階段。但是“報表設計(report design)”也可以用JasperReports API 以編程的方式在內存中構造.隨JasperReports 項目源文件一起提供了一個 noxmldesign(No Xml Design) 例子介紹了如何直接在內存中創(chuàng)

5、建“報表設計(report design)”,而不用編輯Xml 文檔。Normally, the report designs are defined in XML files with a special structure that we shall see in detail later and are subject to the JasperReports compilation process before being filled with data. But they also can be constructed in-memory, programmatically, us

6、ing the JasperReports API. There is a sample called noxmldesign shipped with the JasperReports project source files that shows how to directly create in-memory report designs, without editing any XML files at all.4.1 DTD 文件引用用Xml 文檔來編輯“報表設計(report design)”時,JasperReports 用它自己內部專用的DTD 文件來校驗這個文檔內容。如果X

7、ML 校驗通過,那表示這個XML “報表設計(report design)”符合 JasperReports 所需要的XML 文檔結構和語法,JapserReports 引擎也可以編譯這個文檔來輸出“已編譯”的“報表設計(report design)”.When working with XML report designs, JasperReports uses its own internal DTD files to validate the XML content it receives for processing. If the XML validation is passed,

8、it means that the supplied report design corresponds to the JasperReports required XML structure and syntax and the engine is able to generate the compiled version of the report design.正確的Xml“報表設計”通常標明用于校驗它本身的JasperReports 內部專用的DTD文件。如果不標明引用這個文件,報表編譯便會失敗。這個應該不復雜,因為這個引用在每個“報表設計(report design)“里通常都是一樣

9、,你只要簡單的復制他就行了。初始設計報表,你可以從本書的例子 里復制。 Valid XML report designs always point to the JasperReports internal DTD files for validation. Without the DTD reference specified, the report compilation process fails abruptly. This should not be considered a too much burden for anybody since the DTD reference is

10、 always the same and can simply be copied from previous report designs. At the beginning you will copy it from the supplied samples.前面已經說過,Jasper reports 引擎只認識指向它內部DTD文件的引用,所以大蝦你不要從library 源文件里另外拷貝一個DTD文件放到別的所在,然后在你的“報表設計“里指向它做外部引用。如果你預謀這樣做,你還得修改一些library Classes,包括 類。As already mentioned, the engin

11、e recognizes only the DTD references that point to its internal DTD files. You cannot make a copy of the DTD files found among the library source files and point to that copy in your XML report designs. If you want to do that, you will also have to alter the code of some of the library classes inclu

12、ding the dori.jasper.engine.xml.JRXmlDigester class.如果“小強”你有福遇到了說 JasperReport 引擎由于資源載入問題找不到它自己內部DTD專用文件,確認排除一切可能的錯誤后再做外部DTD文件引用做“強人”。不過遇到這樣錯誤的機率很小,因為library資源載入機制已經作了優(yōu)化。If you ever encounter problems such as the engine not finding its own internal DTD files due to some resource loading problems, ma

13、ke sure you have eliminated every possible cause before deciding to use external DTD files. Encountering such a problem is very unlikely since the resource loading mechanism of the library was improved with time.在XML”報表設計”里,有兩種方式的DTD文件引用,它們是:或者是XML“報表設計”的根元素是,下面是一個普通的XML文件形式的“報表設計”:。第一個連續(xù)的3個點號是放報表的屬

14、性和設置的,另外3個點號是放各種“報表設計”元素的如:parameters,fields,variables,groups,sections, 等。我們會在接下來的幾章里詳細分析它們。The first 3 points make it for the report design properties and settings and the other 3 for the suppressed various report design elements such as report parameters, fields, variables, groups, report sections

15、, etc. We shall see all of them in detail in the following chapters of this book.42 XML 編碼 使用不同種類的語言設計報表時,大哥你一定要注意你報表里的語言編碼要符合XML 文件頭部的encoding屬性所指定的編碼。如果不指定的話,默認的就是“UTF8”編碼。When creating XML report designs in different languages, a special attention should be accorded to the encoding attribute that

16、 can be used in the header of the XML file. By default, if no value is specified for this attribute, the XML parser uses UTF-8 as the encoding for the content of the XML file.羅嗦這一點很重要,因為你如果人工制造XML “報表設計“文件的話,你經常會引入本土語言文本。This important because the report design often contains localized static texts,

17、 which are introducedwhen manually editing the XML file.對于大多數西歐語言,“ISO88591“編碼,也稱作”LATIN1(拉丁語)”,應該足夠滿足處理包括法語在內特殊字符。For most of the West European languages, the ISO-8859-1 encoding, also known as LATIN1, should be sufficient to deal with special characters like , , , , that we have in French for exam

18、ple.具體到每種語言設計的報表,所最合適的編碼類型,請您查詢相關的XML文檔。(修理它)_To find out what is the exact encoding type to specify when editing XML files in a particular language, you have to check the XML documentation. FIXME43報表屬性我們已經知道,XML文件形式的“報表設計”的根元素。這一節(jié)我們將會詳細的看一下這個整張報表的各種屬性以及在XML文件里分別由誰對應它們。We have already seen that is t

19、he root element of an XML report design. In thissection will get to know in detail what are the properties of a report design objects and what is are the XML attributes that correspond to them.Report Name 每個“報表設計”都必須有一個名字(Name)。這很重要,因為JasperReport要用它生成各種文件,特別是在報表編譯,填充,導出時默認參數要使用時。 Every report desig

20、n has to have a name. Its name is important because the library uses it whengenerating files, especially when the default behavior is preferred for compiling, filling or exporting the report.報表的名稱 用的name屬性指定,這個屬性時必填的。而且不允許有空格,必須是單個詞。The name of the report is specified using the name attribute of the

21、 element and ismandatory. Spaces are not allowed in the report name, which has to be one word.Colum Count JasperReports 允許在每頁創(chuàng)建多個列,就像下面這副圖一樣,它由兩列: 默認的,JasperReport引擎每頁創(chuàng)建一個列。Print Order對于有多個列的報表,指定列的填充順序很重要。可以用printOrder屬性指定。屬性值有兩種:豎向填充:列的填充順序為從上到下,從左到右。(printOrder=”Vertical”)橫向填充:列的填充順序為從左到右,從上到下。(p

22、rintOrder=”Horizontal”)圖6即說明了這兩種填充方式。默認的:printOrder=”Vertical”For the reports having more that one column, is important to specify the order in which the columns will be filled and this can be done using the printOrder attribute of the element. There are two possible situations:Vertical filling: Sel

23、ecting this option will ensure the columns are filled from top to bottom and left to right (printOrder=Vertical).Horizontal filling: Columns are filled from left to right and top to bottom (printOrder=Horizontal). The default print order is: printOrder=VerticalPage Size有兩個屬性可以指定要打印出的報表文檔的大?。簆ageWidt

24、h 和pageHeight. 像所有其它的JasperReports 元素指定大小和位置的屬性一樣,它們都以像素為單位。JasperReports使用Java默認的映射72點每英寸。這意味著,如果設置 pageWidth=595 ,那么映射的實際紙張大小為8.26英寸,恰好時A4織的寬度。這兩個屬性默認都設置為A4紙的大?。?pageWidth=”595” pageHeight=”842”There are two attributes at this level to specify the page size of the document that is going to begener

25、ated: pageWidth and pageHeight. Like all the other JasperReports attributes that represent element dimensions and position, those should be specified in pixels. JasperReports uses the default Java resolution of 72 dots per inch. This means that a pageWidth=595 will make about 8.26 inches, which is r

26、oughly the width of an A4 paper. The default page size corresponds to an A4 paper: pageWith=595 pageHeight=842Page OrientationOrientation 屬性確定將要打印的報表紙張的鋪放方向,可以是豎鋪(A4紙正常放)或橫鋪(A4紙橫者放)。The orientation attribute is used to specify whether we are creating documents using the Portraitor the Landscape form

27、ats.如果你從豎鋪Portrait轉為橫鋪Landscape,你還得必須修改pagewidth 和pageheight 屬性。JasperReports requires you to adapt the page width and the page height when switching from Portrait documents to Landscape or vice-versa.例如: 若你要豎鋪A4紙,那么報表的屬性大約應設計為:pageWidth=595 pageHeight=842 orientation=Portrait 若你要橫鋪A4紙,那么報表 的屬性必須改為:

28、pageWidth=842 pageHeight=595 orientation=LandscapeLets see an example: We assume that we want to create an A4 report using the Portrait layout.An A4 has approximately this size: pageWidth=595 pageHeight=842 orientation=PortraitIf we decide to use the Landscape layout for our A4 document, we have to

29、make sure we modify the page with and page height accordingly, like in the following:pageWidth=842 pageHeight=595 orientation=Landscape這是因為,jasperreports 必須知道將要打印紙張的絕對寬度和高度,而且至少在填充報表時,它不會考慮我們對orientation屬性所設的值。This is because JasperReports has to know exactly the absolute width and height of the pag

30、es it will draw on, and does not necessarily consider the value that we supply in the orientation attribute, at least not at report filling time.Orientation 屬性只有在實際打印時才有用,它來通知打印機或其他輸出設備頁面的的鋪放方向。 默認設置為豎向,orientation= Portrait;This orientation attribute is only useful at report printing time, to infor

31、m the printer about the pageorientation or in some special exporters. The default page orientation is Portrait.page Margins 文檔大小確定以后,你就可以指定jasperreports 引擎在產生報表時應該預留多大的頁邊距。頁邊距有四個屬性指定:topMargin ,leftMargin,bottomMargin 和rightMargin.(圖6已有說明)。默認設置上,下頁邊距為20像素,左右為30像素。Once the page size decided, you can

32、specify what margins should the reporting engine preserve when generating the reports. And there are 4 attributes for the job: topMargin, leftMargin,bottomMargin and rightMargin (figure 6). There is a 20 pixels default margin for the top and bottom of the page and a 30 pixels default margin for the

33、right and left margins.Column Size and Spacing 在前面說明ColumnCount 屬性時,我們已經說明報表可以有多個列。 報表引擎必須知道每個列有多寬,每列之間的間隔有多大,這由ColumnWidth 和ColumnSpacing 屬性指定。Reports may have more that one column, as we have already seen when we have talked about thecolumnCount attribute above. But the reporting engine has to kno

34、w how large a column can be and what space should it let between columns. There are two attributes for this job: columnWidth and columnSpacing.在編譯“報表設計”時,JasperReports 會同樣校驗一下所有列的寬度和所有的列間隔是否與指定的頁面寬度和頁邊距相符合。There is also a validation check performed when we compile the report designs, that do not let

35、 us create reports in which the width of the overall columns and the space between does not fit on the specified page width and page margins. 因為jasperreports默認只有一列,所以列間隔默認為0像素,列寬是頁面默認寬度減去默認左右頁邊距為555像素。Since there is only one column by default, the default column spacing is 0 pixels and the defaultco

36、lumn width is equal to the default page width, minus the default left and right margins, which make 555 pixels.Empty Data Source Behavior有時,我們?yōu)閳蟊碇付ǖ臄祿赡転榭占唧w輸出什么我們不能確定。Sometimes the data source that we supply to our reports has no records in it. In this case, it is not clear what the output should

37、 be.可能希望輸出一張空文檔,有時希望輸出報表的某些部分。Some may expect to see a blank document in these situations and others might want to have some of the report sections displayed anyway.我們可以指定一個whenNoDataType屬性來指定發(fā)生這種情況時文檔的輸出結果。There is an attribute called whenNoDataType that lets you decide how the generated document s

38、hould look when there is no data in the data source supplied to it.有三個屬性值可選:Empty document: 產生的報表文檔為空,沒有一頁。Viewers 在裝入這種文當時 會拋出異常。(whenNoDataType=”NoPages”).Blank page: 產生一頁空的文檔。(whenNoDataType=”BlankPage”).All sections displayed: 報表文檔會產生除了detail 部分以外所有的其他部分。(whenNoDataType=AllSectionsNoDetail). 默認值

39、:whenNoDataType=NoPages.There are 3 possibilities you can choose from:Empty document: The generated document will have no pages in it. Viewers might throw an error when trying to load such documents (whenNoDataType=NoPages).Blank page: The generated document will contain a single blank page(whenNoDataType=BlankPage).All sections displayed:

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經權益所有人同意不得將文件中的內容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
  • 6. 下載文件中如有侵權或不適當內容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論