JasperReports最终用户手册中文版第四章报表设计_第1页
JasperReports最终用户手册中文版第四章报表设计_第2页
JasperReports最终用户手册中文版第四章报表设计_第3页
JasperReports最终用户手册中文版第四章报表设计_第4页
JasperReports最终用户手册中文版第四章报表设计_第5页
已阅读5页,还剩3页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、第四章报表设计注:CJSDN.COM haibo 译转载请注明译者和出处ethonsmith"报表设计(report design)”是一个模板,JasperReports引擎会用它来传递动态内容到 打印机,屏幕或者是Web页面。存储于数据库中的数据会根据报表的实际设计来填充整个报表,打印到页面导向的文档。The report desig n represe nts a template that will be used by the JasperReports engine to deliver dynamic content to the printer, to the scr

2、een or to the Web. Data stored in the database is orga ni zed duri ng the report filli ng process accordi ng to this report desig n to obta in ready to print, page orie nted docume nts.通常,一个"报表设计"包含了关于数据填充后所形成的报表(docume nts)的结构和所有的其他方面的信息。这些信息包括将要输岀到报表上的各种文本,图像元素的位置,内容, 以及要进行的数据计算,自定义计算,分组

3、,操作等信息。Gen erally speak ing, a report desig n contains all the in formatio n concerning the structure and the aspect of the docume nts that will be gen erated whe n the data will be provided. This in formati on concerns the positi on and the content of various text or graphic eleme nts that will app

4、ear on the docume nt, their appeara nee, the custom calculati ons, data group ing and data man ipulati on that should be performed whe n gen erati ng the docume nts, etc.一般,"报表设计(report design )"用一种特殊的结构定义在Xml文档中(我们会在稍后详细分析),在被填充数据前,这一过程属于JasperReports报表的编辑阶段。但是"报表设计(report design)&qu

5、ot;也可以用JasperReports API以编程的方式在内存中构造.随JasperReports项目源文件一起提供了一个 noxmldesign ( No Xml Design )例子介绍了如何直接在内存中创建"报表设计 (report design) ”,而不用编辑 Xml文档。Normally, the report desig ns are defi ned in XML files with a special structure that we shall see in detail later and are subject to the JasperReports

6、 compilation process before being filled with data. But they also can be con structed in-memory, programmatically, using the JasperReports API.There is a sample called no xmldesig n shipped with the JasperReports project source files that shows how to directly create in-memory report desig ns, witho

7、ut edit ing any XML files at all.4.1 DTD文件引用用Xml文档来编辑"报表设计(report design )"时,JasperReports用它自己内部专用的 DTD文件来校验这个文档内容。如果 XML校验通过,那表示这个 XML “报表设计(report design) ”符合 JasperReports所需要的XML 文档结构和语法, JapserReports引擎也可以编译 这个文档来输岀"已编译"的"报表设计( report design ) ”.When work ing with XML re

8、port desig ns, JasperReports uses its own internal DTD files to validate the XML content it receives for process in g. If the XML validati on is passed, it means that the supplied report desig n corresp onds to the JasperReports required XML structure and syn tax and the engine is able to gen erate

9、the compiled version of the report desig n.正确的Xml “报表设计"通常标明用于校验它本身的 JasperReports内部专用的DTD文件。 如果不标明引用这个文件,报表编译便会失败。这个应该不复杂,因为这个引用在每个“报表设计(report design )"里通常都是一样,你只要简单的复制他就行了。初始设计报表,你可以从 本书的例子 里复制。Valid XML report desig ns always point to the JasperReports internal DTD files for validati o

10、n. Without the DTD reference specified, the report compilati on process fails abruptly. This should not be con sidered a too much burde n for an ybody since the DTD reference is always the same and can simply be copied from previous report desig ns. At the begi nning you will copy it from the suppli

11、ed samples.前面已经说过,Jasper reports引擎只认识指向它内部DTD文件的引用,所以大虾你不要从library源文件里另外拷贝一个DTD文件放到别的所在,然后在你的“报表设计“里指向它-做外部引用。如果你预谋这样做,你还得修改一些library Classes,包括dori.jasper.e ngin e.xml.JRXmlDigester类。As already mentioned, the engine recognizes only the DTD references that point to its internal DTD files. You cannot

12、 make a copy of the DTD files found among the library source files and point to that copy in your XML report desig ns. If you want to do that, you will also have to alter the code of some of the library classes including the dori.jasper.engine.xml.JRXmlDigester class.如果“小强”你有福遇到了说JasperReport引擎由于资源载

13、入问题找不到它自己内部 DTD专用文件,确认排除一切可能的错误后再做外部DTD文件引用做“强人”。不过遇到这样错误的机率很小,因为library资源载入机制已经作了优化。If you ever encounter problems such as the engine not finding its own internal DTD files due to some resource loadi ng problems, make sure you have elim in ated every possible cause before deciding to useexternal DT

14、D files. Encountering such a problem is very unlikely since theresource loadi ng mecha nism of the library was improved with time.在XML ”报表设计”里,有两种方式的 DTD文件引用,它们是:<!DOCTYPE jasperReport PUBLIC "-/JasperReports/DTD Report Design/EN""或者是<!DOCTYPE jasperReport PUBLIC "-/JasperR

15、eports/DTD Report Design/EN""XML “报表设计”的根元素是<jasperReport>,下面是一个普通的XML文件形式的“报表设计”:<?xml version="1.0"?><!DOCTYPE jasperReport PUBLIC "-/JasperReports/DTD Report Design/EN""vjasperReport name="name_of_the_report"。>o oo</jasperReports&g

16、t;第一个连续的3个点号是放报表的属性和设置的,另外3个点号是放各种“报表设计”元素的如:parameters,fields,variables,groups,sections,等。我们会在接下来的几章里详细分析它 们。The first 3 points make it for the report desig n properties and sett in gs a nd the other 3 for the suppressed various report desig n eleme nts such as report parameters, fields, variables,

17、 groups, report sect ions, etc. We shall see all of them in detail in the follow ing chapters of this book.4. 2 XML编码使用不同种类的语言设计报表时,大哥你一定要注意你报表里的语言编码要符合XML文件头部的encoding属性所指定的编码。如果不指定的话,默认的就是“ UTF 8”编码。When creati ng XML report desig ns in differe nt Ian guages, a special atte nti on should be accord

18、ed to the encoding attribute that 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 de

19、sign often contains localized static texts, which are introduced whe n man ually edit ing the XML file.对于大多数西欧语言,“ISO 8859 1 “编码,也称作”LATIN1 (拉丁语)”,应该足够满足处理包括法语在内特殊字符。For most of the West European Ianguages, the "ISO-8859-1" encoding, also known as LATIN1, should be sufficient to deal with

20、special characters like , a, ,e?, that we have in French for example.<?xml version="1.0" encoding="ISO-8859-1"?><!DOCTYPE jasperReport PUBLIC "-/JasperReports/DTD Report Design/EN""vjasperReport name="name_of_the_report" . ></jasperReports&

21、gt;具体到每种语言设计的报表,所最合适的编码类型,请您查询相关的XML文档。(修理它)To find out what is the exact encoding type to specify when editing XML files in a particularIan guage, you have to check the XML docume ntatio n. FIXME4. 3报表属性我们已经知道,vjasperReport >XML文件形式的“报表设计”的根元素。这一节我们将会详 细的看一下这个整张报表的各种属性以及在XML文件里分别由谁对应它们。We have a

22、lready seen that vjasperReportis the root element of an XML report design. In this sect ion will get to know in detail what are the properties of a report desig n objects and what is are the XML attributes that corresp ond to them.Report Name每个“报表设计"都必须有一个名字(Name)。这很重要,因为 JasperReport要用它生成各种文件,

23、特别是在报表编译,填充,导岀时默认参数要使用时。Every report desig n has to have a n ame. Its n ame is importa nt because the library uses it whe ngenerating files, especially when the default behavior is preferred for compiling, filling or export ing the report.报表的名称 用vjasperReport >的name属性指定,这个属性时必填的。而且不允许有空格, 必须是单个词。

24、The name of the report is specified using the name attribute of the <jasperReport> element and is man datory. Spaces are not allowed in the report n ame, which has to be one word.Colum CountJasperReports允许在每页创建多个列,就像下面这副图一样,它由两列:VERTICAL I ILLINGHORIZONTAL FILLINGCOLUMN HEADERcolumn spacing QC

25、OLUMN HEADER+ column vwdth口 ET机DETAILIDETAL DETAILDETAILDETAILDETAIL、A*FGOLUMB FOOTERCOLUMN FOOTERPAGE HEADERtop margin QPAGE HEADERbottomPAGE HEADERCOLUMN HEADIERCOLUMN HEADERRDETAILDETALDETAILDETAI.DETAILDETAILDETAtDETAILCOLUMN FOOTERCOLUMN FOOTER.PAGE HEADER默认的,JasperReport引擎每页创建一个列Print Order对于有

26、多个列的报表,指定列的填充顺序很重要。可以用prin tOrder属性指定。属性值有两种:printOrder= "Vertical ”prin tOrder= "Horiz on tai ”1.竖向填充:列的填充顺序为从上到下,从左到右。( 2.横向填充:列的填充顺序为从左到右,从上到下。(图6即说明了这两种填充方式。默认的:prin tOrder= "Vertical"For the reports having more that one column, is important to specify the order in which the

27、columns will be filled and this can be done using the printOrder attribute of the <jasperReport> eleme nt. There are two possible situati ons:Vertical filling : Selecting this option will ensure the columns are filled from top to bottom and left to right (printOrder="Vertical").Horiz

28、ontal filling : Columns are filled from left to right and top to bottom(pri ntOrder="Horizo ntal"). The default print order is: prin tOrder="Vertical"Page Size有两个属性可以指定要打印出的报表文档的大小:pageWidth和pageHeight.像所有其它的JasperReports元素指定大小和位置的属性一样,它们都以像素为单位。JasperReports使用Java默认的映射72点每英寸。这意味

29、着,如果设置 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 be gen erated: pageWidth and pageHeight. Like all the other JasperReports attribut

30、es that represe nf| eleme nt dime nsions and positi on, those should be specified in pixels. JasperReports uses the | default Java resoluti on of 72 dots per in ch. This means that a pageWidth="595" will make about 8.26 in ches, which is roughly the width of an A4 paper. The default page s

31、ize corresp onds to an A4 paper: pageWith="595" pageHeight="842"Page OrientationOrientation属性确定将要打印的报表纸张的铺放方向,可以是竖铺(A4纸正常放)或横铺(A4纸横者放)。The orientation attribute is used to specify whether we are creating documents using the "Portrait" or the "La ndscape" forma

32、ts.如果你从竖铺 Portrait转为横铺Landscape,你还得必须修改 pagewidth 和pageheight属性。 JasperReports requires you to adapt the page width and the page height whe n switch ing from "Portrait" docume nts to "La ndscape" or vice-versa.例如:若你要竖铺A4纸,那么报表的属性大约应设计为 :pageWidth="595" pageHeight="

33、842" orientation="Portrait"若你要横铺A4纸,那么报表的属性必须改为:pageWidth="842" pageHeight="595" orien tatio n="La ndscape"Let's see an example: We assume that we want to create an A4 report using the "Portrait" layout. An A4 has approximately this size: pa

34、geWidth="595" pageHeight="842" orientation="Portrait" If we decide to use the "La ndscape" layout for our A4 docume nt, we have to make sure we modify the page with and page height accord in gly, like in the follow ing:pageWidth="842" pageHeight=&quo

35、t;595" orien tatio n="La ndscape"这是因为,jasperreports必须知道将要打印纸张的绝对宽度和高度,而且至少在填充报表时,它不会考虑我们对 orie ntation属性所设的值。This is because JasperReports has to know exactly the absolute width and height of the pages it will draw on, and does not necessarily consider the value that we supply in the

36、orientation attribute, at least not at report filling time.Orientation属性只有在实际打印时才有用,它来通知打印机或其他输出设备页面的的铺放方向。默认设置为竖向,orie ntatio n= Portrait;This orientation attribute is only useful at report printing time, to inform the printer about the page orientation or in some special exporters. The default pag

37、e orientation is "Portrait".page Margins文档大小确定以后,你就可以指定 jasperreports引擎在产生报表时应该预留多大的页边 距。页边距有四个属性指定:topMargin ,leftMargin, bottomMargin 和 rightMargin .(图 6已有说明)。默认设置上,下页边距为20像素,左右为30像素。Once the page size decided, you can specify what margins should the report ing engine preserve whe n gen

38、erati ng the reports. And there are 4 attributes for the job: topMargi n, leftMargi n, bottomMarg in and rightMarg in (figure 6). There is a 20 pixels default margin for the top and bottom of the page and a 30 pixels default marg in for the right and left marg ins.Column Size and Spacing在前面说明ColumnC

39、ount属性时,我们已经说明报表可以有多个列。报表引擎必须知道每个列有多宽,每列之间的间隔有多大,这由ColumnWidth和ColumnSpacing 属性指定。Reports may have more that one colu mn, as we have already see n whe n we have talked about the colu mnCount attribute above. But the report ing engine has to know how large a colu mn can be and what space should it le

40、t between columns. There are two attributes for this job: columnWidth and colu mn Spac ing.在编译"报表设计”时,JasperReports会同样校验一下所有列的宽度和所有的列间隔是否与指定的页面宽度和页边距相符合。There is also a validati on check performed whe n we compile the report desig ns, that do not let us create reports in which the width of the

41、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 colu mn by default, the default colu mn spaci ng is 0 pixels and the default colu mn width is equal to the default page w

42、idth, minus the default left and right margins, which make 555 pixels.Empty Data Source Behavior有时,我们为报表指定的数据集可能为空集,具体输出什么我们不能确定。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 be.可能希望输出一张空文档,有时希望输出报表的某些部分。Some may ex

43、pect to see a blank document in these situations and others might w ant to have some of the report secti ons displayed any way.我们可以指定一个 whenNoDataType属性来指定发生这种情况时文档的输出结果。There is an attribute called whe nN oDataType that lets you decide how the gen erated docume nt should look whe n there is no data

44、 in the data source supplied to it.有三个属性值可选:Empty document:产生的报表文档为空,没有一页。Viewers在装入这种文当时会抛出异常。(whe nN oDataType =" NoPages").Bla nk page:产生一页空的文档。(whe nN oDataType = "Bla nkPage").All sections displayed :报表文档会产生除了 detail部分以外所有的其他部分。(whenNoDataType="AIISectionsNoDetail").默认值:whe nN oDataType ="NoPages".There are 3 possibilities you can choose from:Empty docume nt: The gen erated docume nt will have no pages in it. Viewers might throw anerror whe n trying to load such docume nts (whe nN oDataType="NoPages").Blank page : The gen erated docume nt

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

最新文档

评论

0/150

提交评论