




已阅读5页,还剩2页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
第四章 报表设计 注:CJSDN.COM haibo译 转载请注明译者和出处 “报表设计(report design)”是一个模板,JasperReports 引擎会用它来传递动态内容到打印机,屏幕或者是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 database 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 information 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 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) 例子介绍了如何直接在内存中创建“报表设计(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, using 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 文件来校验这个文档内容。如果XML 校验通过,那表示这个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, 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)“里通常都是一样,你只要简单的复制他就行了。初始设计报表,你可以从本书的例子 里复制。 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 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,包括dori.jasper.engine.xml.JRXmlDigester 类。As already mentioned, the engine 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 including the dori.jasper.engine.xml.JRXmlDigester class.如果“小强”你有福遇到了说 JasperReport 引擎由于资源载入问题找不到它自己内部DTD专用文件,确认排除一切可能的错误后再做外部DTD文件引用-做“强人”。不过遇到这样错误的机率很小,因为library资源载入机制已经作了优化。If you ever encounter problems such as the engine not finding its own internal DTD files due to some resource loading problems, make 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文件形式的“报表设计”:。第一个连续的3个点号是放报表的属性和设置的,另外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, 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 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, 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 example.具体到每种语言设计的报表,所最合适的编码类型,请您查询相关的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文件形式的“报表设计”的根元素。这一节我们将会详细的看一下这个整张报表的各种属性以及在XML文件里分别由谁对应它们。We have already seen that is the 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.n Report Name 每个“报表设计”都必须有一个名字(Name)。这很重要,因为JasperReport要用它生成各种文件,特别是在报表编译,填充,导出时默认参数要使用时。 Every report design 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 element and ismandatory. Spaces are not allowed in the report name, which has to be one word.Colum Count JasperReports 允许在每页创建多个列,就像下面这副图一样,它由两列: 默认的,JasperReport引擎每页创建一个列。Print Order对于有多个列的报表,指定列的填充顺序很重要。可以用printOrder属性指定。属性值有两种:1 竖向填充:列的填充顺序为从上到下,从左到右。(printOrder=”Vertical”)2 横向填充:列的填充顺序为从左到右,从上到下。(printOrder=”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: Selecting 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有两个属性可以指定要打印出的报表文档的大小:pageWidth 和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 begenerated: 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 roughly 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 formats.如果你从竖铺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纸,那么报表 的属性必须改为: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 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 pages 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 inform 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 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 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 know 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 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 defaultcolumn width is equal to the default page width, 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 expect to see a blank document in these situations and others might want to have some of the report sections displayed anyway.我们可以指定一个whenNoDataType属性来指定发生这种情况时文档的输出结果。There is an attribute called whenNoDataType that lets you decide how the generated document should 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). 默认值: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: All the report sections ex
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025-2030中国动力电池回收利用体系建设与经济效益分析报告
- 2025-2030中国制药用水系统验证标准实施报告
- 2025-2030中国冷链物流行业发展瓶颈及解决方案研究报告
- 2025至2030现汇贷款产业市场深度分析及前景趋势与投资报告
- 2025年智能眼镜的智能设备
- 2025年海洋能源开发技术创新探索
- 2025广东韶关乐昌市九峰镇村基层公共服务站系统操作员招聘2人模拟试卷附答案详解(考试直接用)
- 2025贵州安顺市参加“第十三届贵州人才博览会”引才271人考前自测高频考点模拟试题及答案详解(易错题)
- 2025广东东莞东坑镇松实东中招聘镇聘教师27人模拟试卷及答案详解(夺冠系列)
- 2025年襄阳市襄州区“田园诗乡·才聚襄州”引进36名事业单位急需紧缺人才(华中师范大学站)考前自测高频考点模拟试题及答案详解(历年真题)
- 股权代持协议(模板)8篇
- 《AI创意课件之设计》课件
- 会计中级职称《财务管理》电子书
- 河南豫信电科所属公司招聘笔试题库2025
- 小学生科普恐龙知识课件
- 2025年广东省房屋安全鉴定员理论考试题库-上(单选题)
- 高考文言文120个常见实词积累练习(学生版)
- 《STEMI再灌注治疗策略》课件
- 配电网安健环设施标准
- 人教版三年级语文上册第一次月考试卷及答案(A4打印版)
- 2025年全国共青团团员知识竞赛题库及答案(共150题)
评论
0/150
提交评论