iReport-JasperReports 报表开发指南
iReport-JasperReport
报表开发指南
上海锐道信息技术有限公司 高杰
www.bstek.com
1
iReport-JasperReports 报表开发指南
目 录
1 Introduction....................................................................................................................................4
2 Getting started................................................................................................................................5
2.1 Requirements ......................................................................................................................5
2.3 Download............................................................................................................................5
3 Basic notions of JasperReports ......................................................................................................6
3.1 Jasperreorts..........................................................................................................................6
3.2 The report life cycle ............................................................................................................6
4 Report Structure.............................................................................................................................7
4.1 Bands...................................................................................................................................7
5 Report elements............................................................................................................................12
6 Fonts and Styles ...........................................................................................................................14
6.1 The font.............................................................................................................................14
6.2 Styles.................................................................................................................................16
7. Fields,Parameters,Variable .........................................................................................................22
7.1 Fields.................................................................................................................................22
7.2 Parameters.........................................................................................................................26
7.3 Variables............................................................................................................................32
8 Bands and groups.........................................................................................................................35
8.1 Bands.................................................................................................................................35
8.2 Groups...............................................................................................................................37
9 SubReport ....................................................................................................................................44
9.1 create a SubReport ............................................................................................................44
9.2 Passage of the parameters .................................................................................................45
9.3 SubReport sample .............................................................................................................47
10 DataSource.................................................................................................................................56
10.1 DataSource in iReport.....................................................................................................56
10.2 JDBC Connection............................................................................................................59
10.3 The JRDataSource Interface............................................................................................63
10.4 JavaBean set datasource..................................................................................................64
10.5 JREmptyDataSource .......................................................................................................69
10.6 HQL and Hibernate connection.......................................................................................70
10.7 How to implement a new JRDataSource.........................................................................71
11 Internationalication.....................................................................................................................78
11.1 Resource Bundle Base Name ..........................................................................................78
11.2 Retrieval of localized strings...........................................................................................81
12 Scriptlet......................................................................................................................................82
12.1 JRAbstractScriptlet .........................................................................................................82
13 Template.....................................................................................................................................85
13.1 Template structure...........................................................................................................85
2
iReport-JasperReports 报表开发指南
13.2 Using a custom template.................................................................................................88
13.3 Put templates in jar files..................................................................................................90
14 Chart...........................................................................................................................................92
14.1 First chart ........................................................................................................................92
14.2 Datasets...........................................................................................................................99
14.3 Properties of the charts..................................................................................................100
15 SubDataset ...............................................................................................................................101
15.1 Creating a subdataset.....................................................................................................101
15.2 Dataset runs...................................................................................................................103
16 CrossTabs................................................................................................................................. 111
16.1 Crosstab wizard.............................................................................................................111
16.2 Columns,rows,cells .......................................................................................................116
16.2.1 Rows and columns .............................................................................................116
16.2.2 cells ....................................................................................................................125
16.2.3 Special cells........................................................................................................126
16.2.4 Measures ............................................................................................................127
16.2.5 Crosstab element properties...............................................................................128
16.2.6 Crosstab parameters ...........................................................................................130
16.2.7 Crosstab data......................................................................................................132
16.2.8 crosstab total variables.......................................................................................133
17 jrxml file introduce...................................................................................................................135
3
iReport-JasperReports 报表开发指南
1 Introduction
iReport 是一个开源项目,它使用 Jasperreports 来创建复杂的报表效果。它 100%使用
Java 语言编写。
iReport 提供了可视化的报表设计环境,通过 iReport 我们可以快速的创建一个
Jasperreports 报表。在下面的内容当中将使用 iReport 的最新版 2.0.1 详细介绍如何使用
iReport 来创建复杂的 JasperReports 报表。
4
iReport-JasperReports 报表开发指南
2 Getting started
在本章中我们将一起看一下 iReport 运行时所需要的环境、如何获得 iReport 源码/安装
文件及如何在我们的系统中安装使用它。
2.1 Requirements
iReport 的最新版式是 2.01,它运行时需要 sun java2 SDK 1.5 及以上版本,为了能编译
我们的报表文件我们需要完整的安装 JDK。
2.3 Download
我们可以从下列网站下载到 iReport 的安装文件及源码:
http://sourceforge.net/projects/ireport
在该网站中我们可以根据需要下载合适的版本,目前最新版是 2.01,我们推荐下载最
新的版本,下载完成后根据不同的版本解压或安装后即可使用(使用前请确保你的机器上
安装好了 SUN JDK)。
5