




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、第四章 報(bào)表設(shè)計(jì) “報(bào)表設(shè)計(jì)(report design)”是一個(gè)模板,JasperReports 引擎會(huì)用它來傳遞動(dòng)態(tài)內(nèi)容到打印機(jī),屏幕或者是Web頁面。存儲(chǔ)于數(shù)據(jù)庫中的數(shù)據(jù)會(huì)根據(jù)報(bào)表的實(shí)際設(shè)計(jì)來填充整個(gè)報(bào)表,打印到頁面導(dǎo)向的文檔。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.通常,一個(gè)“報(bào)表設(shè)計(jì)”包含了關(guān)于數(shù)據(jù)填充后所形成的報(bào)表(documents)的結(jié)構(gòu)和所有的其他方面的信息。這些信息包括將要輸出到報(bào)表上的各種文本,圖像元素的位置,內(nèi)容,以及要進(jìn)行的數(shù)據(jù)計(jì)算,自定義計(jì)算,分組,操作等信息。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.一般,“報(bào)表設(shè)計(jì)(report design)”用一種特殊的結(jié)構(gòu)定義在Xml文檔中(我們會(huì)在稍后詳細(xì)分析),在被填充數(shù)據(jù)前,這一過程屬于JasperReports 報(bào)表的編輯階段。但是“報(bào)表設(shè)計(jì)(report design)”也可以用JasperReports API 以編程的方式在內(nèi)存中構(gòu)造.隨JasperReports 項(xiàng)目源文件一起提供了一個(gè) noxmldesign(No Xml Design) 例子介紹了如何直接在內(nèi)存中創(chuàng)
5、建“報(bào)表設(shè)計(jì)(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 文檔來編輯“報(bào)表設(shè)計(jì)(report design)”時(shí),JasperReports 用它自己內(nèi)部專用的DTD 文件來校驗(yàn)這個(gè)文檔內(nèi)容。如果X
7、ML 校驗(yàn)通過,那表示這個(gè)XML “報(bào)表設(shè)計(jì)(report design)”符合 JasperReports 所需要的XML 文檔結(jié)構(gòu)和語法,JapserReports 引擎也可以編譯這個(gè)文檔來輸出“已編譯”的“報(bào)表設(shè)計(jì)(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“報(bào)表設(shè)計(jì)”通常標(biāo)明用于校驗(yàn)它本身的JasperReports 內(nèi)部專用的DTD文件。如果不標(biāo)明引用這個(gè)文件,報(bào)表編譯便會(huì)失敗。這個(gè)應(yīng)該不復(fù)雜,因?yàn)檫@個(gè)引用在每個(gè)“報(bào)表設(shè)計(jì)(report design)“里通常都是一樣
9、,你只要簡(jiǎn)單的復(fù)制他就行了。初始設(shè)計(jì)報(bào)表,你可以從本書的例子 里復(fù)制。 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.前面已經(jīng)說過,Jasper reports 引擎只認(rèn)識(shí)指向它內(nèi)部DTD文件的引用,所以大蝦你不要從library 源文件里另外拷貝一個(gè)DTD文件放到別的所在,然后在你的“報(bào)表設(shè)計(jì)“里指向它做外部引用。如果你預(yù)謀這樣做,你還得修改一些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.如果“小強(qiáng)”你有福遇到了說 JasperReport 引擎由于資源載入問題找不到它自己內(nèi)部DTD專用文件,確認(rèn)排除一切可能的錯(cuò)誤后再做外部DTD文件引用做“強(qiáng)人”。不過遇到這樣錯(cuò)誤的機(jī)率很小,因?yàn)閘ibrary資源載入機(jī)制已經(jīng)作了優(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”報(bào)表設(shè)計(jì)”里,有兩種方式的DTD文件引用,它們是:或者是XML“報(bào)表設(shè)計(jì)”的根元素是,下面是一個(gè)普通的XML文件形式的“報(bào)表設(shè)計(jì)”:。第一個(gè)連續(xù)的3個(gè)點(diǎn)號(hào)是放報(bào)表的屬
14、性和設(shè)置的,另外3個(gè)點(diǎn)號(hào)是放各種“報(bào)表設(shè)計(jì)”元素的如:parameters,fields,variables,groups,sections, 等。我們會(huì)在接下來的幾章里詳細(xì)分析它們。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 編碼 使用不同種類的語言設(shè)計(jì)報(bào)表時(shí),大哥你一定要注意你報(bào)表里的語言編碼要符合XML 文件頭部的encoding屬性所指定的編碼。如果不指定的話,默認(rèn)的就是“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.羅嗦這一點(diǎn)很重要,因?yàn)槟闳绻斯ぶ圃靀ML “報(bào)表設(shè)計(jì)“文件的話,你經(jīng)常會(huì)引入本土語言文本。This important because the report design often contains localized static texts,
17、 which are introducedwhen manually editing the XML file.對(duì)于大多數(shù)西歐語言,“ISO88591“編碼,也稱作”LATIN1(拉丁語)”,應(yīng)該足夠滿足處理包括法語在內(nèi)特殊字符。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.具體到每種語言設(shè)計(jì)的報(bào)表,所最合適的編碼類型,請(qǐng)您查詢相關(guān)的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報(bào)表屬性我們已經(jīng)知道,XML文件形式的“報(bào)表設(shè)計(jì)”的根元素。這一節(jié)我們將會(huì)詳細(xì)的看一下這個(gè)整張報(bào)表的各種屬性以及在XML文件里分別由誰對(duì)應(yīng)它們。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 每個(gè)“報(bào)表設(shè)計(jì)”都必須有一個(gè)名字(Name)。這很重要,因?yàn)镴asperReport要用它生成各種文件,特別是在報(bào)表編譯,填充,導(dǎo)出時(shí)默認(rèn)參數(shù)要使用時(shí)。 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.報(bào)表的名稱 用的name屬性指定,這個(gè)屬性時(shí)必填的。而且不允許有空格,必須是單個(gè)詞。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)建多個(gè)列,就像下面這副圖一樣,它由兩列: 默認(rèn)的,JasperReport引擎每頁創(chuàng)建一個(gè)列。Print Order對(duì)于有多個(gè)列的報(bào)表,指定列的填充順序很重要。可以用printOrder屬性指定。屬性值有兩種:豎向填充:列的填充順序?yàn)閺纳系较拢瑥淖蟮接摇#╬rintOrder=”Vertical”)橫向填充:列的填充順序?yàn)閺淖蟮接遥瑥纳系较隆#╬
22、rintOrder=”Horizontal”)圖6即說明了這兩種填充方式。默認(rèn)的: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有兩個(gè)屬性可以指定要打印出的報(bào)表文檔的大小:pageWidt
24、h 和pageHeight. 像所有其它的JasperReports 元素指定大小和位置的屬性一樣,它們都以像素為單位。JasperReports使用Java默認(rèn)的映射72點(diǎn)每英寸。這意味著,如果設(shè)置 pageWidth=595 ,那么映射的實(shí)際紙張大小為8.26英寸,恰好時(shí)A4織的寬度。這兩個(gè)屬性默認(rèn)都設(shè)置為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 屬性確定將要打印的報(bào)表紙張的鋪放方向,可以是豎鋪(A4紙正常放)或橫鋪(A4紙橫者放)。The orientation attribute is used to specify whether we are creating documents using the Portraitor the Landscape form
27、ats.如果你從豎鋪Portrait轉(zhuǎn)為橫鋪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紙,那么報(bào)表的屬性大約應(yīng)設(shè)計(jì)為:pageWidth=595 pageHeight=842 orientation=Portrait 若你要橫鋪A4紙,那么報(bào)表 的屬性必須改為:
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這是因?yàn)?jasperreports 必須知道將要打印紙張的絕對(duì)寬度和高度,而且至少在填充報(bào)表時(shí),它不會(huì)考慮我們對(duì)orientation屬性所設(shè)的值。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 屬性只有在實(shí)際打印時(shí)才有用,它來通知打印機(jī)或其他輸出設(shè)備頁面的的鋪放方向。 默認(rèn)設(shè)置為豎向,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 引擎在產(chǎn)生報(bào)表時(shí)應(yīng)該預(yù)留多大的頁邊距。頁邊距有四個(gè)屬性指定:topMargin ,leftMargin,bottomMargin 和rightMargin.(圖6已有說明)。默認(rèn)設(shè)置上,下頁邊距為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 屬性時(shí),我們已經(jīng)說明報(bào)表可以有多個(gè)列。 報(bào)表引擎必須知道每個(gè)列有多寬,每列之間的間隔有多大,這由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.在編譯“報(bào)表設(shè)計(jì)”時(shí),JasperReports 會(huì)同樣校驗(yàn)一下所有列的寬度和所有的列間隔是否與指定的頁面寬度和頁邊距相符合。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. 因?yàn)閖asperreports默認(rèn)只有一列,所以列間隔默認(rèn)為0像素,列寬是頁面默認(rèn)寬度減去默認(rèn)左右頁邊距為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有時(shí),我們?yōu)閳?bào)表指定的數(shù)據(jù)集可能為空集,具體輸出什么我們不能確定。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.可能希望輸出一張空文檔,有時(shí)希望輸出報(bào)表的某些部分。Some may expect to see a blank document in these situations and others might want to have some of the report sections displayed anyway.我們可以指定一個(gè)whenNoDataType屬性來指定發(fā)生這種情況時(shí)文檔的輸出結(jié)果。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.有三個(gè)屬性值可選:Empty document: 產(chǎn)生的報(bào)表文檔為空,沒有一頁。Viewers 在裝入這種文當(dāng)時(shí) 會(huì)拋出異常。(whenNoDataType=”NoPages”).Blank page: 產(chǎn)生一頁空的文檔。(whenNoDataType=”BlankPage”).All sections displayed: 報(bào)表文檔會(huì)產(chǎn)生除了detail 部分以外所有的其他部分。(whenNoDataType=AllSectionsNoDetail). 默認(rèn)值
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等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025員工解除勞動(dòng)合同協(xié)議書范文
- 2025合同終止的具體法律事實(shí)解析
- 2025關(guān)于機(jī)械設(shè)備租賃合同
- 2025深圳市標(biāo)準(zhǔn)商鋪?zhàn)赓U合同范本
- 2025短期臨時(shí)勞動(dòng)合同協(xié)議書
- 2025年深入理解技術(shù)合同與勞務(wù)合同的區(qū)別與聯(lián)系
- 2025精簡(jiǎn)版的購房合同協(xié)議書
- 《全球建筑》課件
- 《常見的健康問題解析》課件
- 《脊柱側(cè)彎的護(hù)理》課件
- 母乳喂養(yǎng)知識(shí)培訓(xùn)課件下載
- 西安市曲江第三中學(xué)行政人員及教師招聘筆試真題2024
- 2025-2030中國竹纖維行業(yè)市場(chǎng)發(fā)展現(xiàn)狀及競(jìng)爭(zhēng)策略與投資前景研究報(bào)告
- 委托外包催收合同協(xié)議
- 2025-2030中國涂裝行業(yè)市場(chǎng)深度分析及發(fā)展預(yù)測(cè)與投資策略研究報(bào)告
- 乳腺癌診治指南與規(guī)范(2025年版)解讀
- 銀行系統(tǒng)招聘考試(經(jīng)濟(jì)、金融、會(huì)計(jì))模擬試卷14
- 心理韌性在咨詢中的重要性試題及答案
- 外研版(三起)(2024)三年級(jí)下冊(cè)英語Unit 2 單元測(cè)試卷(含答案)
- 2025年全國普通話水平測(cè)試訓(xùn)練題庫及答案
- 國開(內(nèi)蒙古)2024年《創(chuàng)新創(chuàng)業(yè)教育基礎(chǔ)》形考任務(wù)1-3終考任務(wù)答案
評(píng)論
0/150
提交評(píng)論