iReport 用户手册
机密 第 1 页 2010-2-5
1
version 1.0
Giulio Toffoli
用户手册
翻译:董岿
Email:qiyan911@gmail.com
Copyright © 2004-2005 by Giulio Toffoli. All rights reserved.
iReport 用户手册
机密 第 2 页 2010-2-5
2
目录
Giulio Toffoli....................................................................................................................................1
1 序言 ..............................................................................................................................................5
什么是 iReport?........................................................................................................................5
功能特点: ..............................................................................................................................6
iReport 社区: ........................................................................................................................6
鸣谢: ......................................................................................................................................7
2 入门 ..............................................................................................................................................7
必要条件: ..............................................................................................................................7
下载: ......................................................................................................................................8
编译 iReport: .........................................................................................................................8
基本的配置: ..........................................................................................................................8
创建 JDBC 连接:.................................................................................................................11
第一个报表: ........................................................................................................................12
命令行选项: ........................................................................................................................16
3 JasperReports 基础概念..............................................................................................................16
JasperReports..........................................................................................................................16
报表生命周期: ....................................................................................................................17
Jrxml 源代码和 jasper 文件:...............................................................................................17
数据源和打印格式: ............................................................................................................21
版本兼容性: ........................................................................................................................22
表达式: ................................................................................................................................23
一个简单的程序: ................................................................................................................24
4 报表结构 ....................................................................................................................................25
Bands ......................................................................................................................................25
Title.................................................................................................................................26
Page header.....................................................................................................................26
Column header................................................................................................................26
Group header...................................................................................................................27
Detail...............................................................................................................................27
Group footer....................................................................................................................27
Column footer.................................................................................................................27
Page footer......................................................................................................................27
Last Page footer ..............................................................................................................27
Summary.........................................................................................................................28
Background.....................................................................................................................28
报表属性: ............................................................................................................................28
列 ....................................................................................................................................29
高级选项: ............................................................................................................................31
脚本: ....................................................................................................................................31
更多… ............................................................................................................................32
iReport 用户手册
机密 第 3 页 2010-2-5
3
Title on a new page 选项:............................................................................................32
Summary on a new page 选项: ....................................................................................34
Floating column footer 选项:......................................................................................34
打印顺序: ....................................................................................................................34
无数据打印(如果没有数据时):.............................................................................35
i18n: .............................................................................................................................35
Resource Bundle Base name........................................................................................35
XML 源文件的编码设置:...........................................................................................36
5 报表元素 ....................................................................................................................................36
选择并插入元素到报表中: ................................................................................................36
布置和元素顺序 ....................................................................................................................39
使用元素树管理元素: ........................................................................................................42
基本属性: ............................................................................................................................42
线 ....................................................................................................................................45
矩形 ................................................................................................................................45
椭圆 ................................................................................................................................46
图象 ................................................................................................................................46
文本元素 ................................................................................................................................49
静态文本 ........................................................................................................................50
文本域 ............................................................................................................................50
子报表 ....................................................................................................................................54
专用元素 ................................................................................................................................55
图表 ................................................................................................................................55
条形码 ............................................................................................................................55
超连接 ....................................................................................................................................57
Reference........................................................................................................................58
LocalAnchor ...................................................................................................................58
LocalPage........................................................................................................................58
RemoteAnchor................................................................................................................58
RemotePage....................................................................................................................58
6 字体 ............................................................................................................................................58
字体 ........................................................................................................................................58
扩展字体 ........................................................................................................................59
编码 ................................................................................................................................60
使用 Unicode 字符.........................................................................................................60
报表字体 ................................................................................................................................60
7 字段,参数和变量 ....................................................................................................................61
字段 ........................................................................................................................................61
SQL 查询的字段注册....................................................................................................62
JavaBean 的字段注册 ....................................................................................................63
JRExtendedBeanDataSource 的字段注册 .....................................................................64
字段和文本域 ................................................................................................................64
参数 ........................................................................................................................................65
在查询中使用参数 ........................................................................................................66
iReport 用户手册
机密 第 4 页 2010-2-5
4
使用程序传递参数 ........................................................................................................66
内置参数 ........................................................................................................................68
变量 ........................................................................................................................................68
内置变量 ........................................................................................................................70
8 Bands and groups.........................................................................................................................70
Bands ......................................................................................................................................70
Groups.....................................................................................................................................71
9 Subreport......................................................................................................................................76
创建子报表 ............................................................................................................................77
连接子报表到父报表 ............................................................................................................77
参数的通道 ....................................................................................................................77
指定数据源 ....................................................................................................................78
指定子报表 ....................................................................................................................79
一步一步举例 ........................................................................................................................79
返回参数 ................................................................................................................................85
10 数据源 ......................................................................................................................................86
iReport 中的数据源 ...............................................................................................................87
JDBC 连接..............................................................................................................................88
ClassNotFoundException ...............................................................................................90
URL 不正确 ...................................................................................................................90
连接参数不正确 ............................................................................................................90
使用 JDBC 连接.............................................................................................................90
字段注册 ........................................................................................................................91
JRDataSource 接口.................................................................................................................92
JavaBean 作为数据源 ............................................................................................................92
JavaBean 的一个字段作为数据源 ................................................................................94
XML 数据源 ..........................................................................................................................95
字段的注册 ....................................................................................................................97
XML 和子报表...............................................................................................................99
CSV 数据源..........................................................................................................................103
字段的注册 ..................................................................................................................104
JREmptyDataSource.............................................................................................................104
实现一个新的 JRDataSource...............................................................................................105
用 iReport 实现个性化的 JRDataSource.............................................................................107
JavaBean Extended 数据源 ..................................................................................................109
11 国际化 ....................................................................................................................................110
Resource Bundle Base Name................................................................................................ 110
恢复本地化字符串 ..............................................................................................................112
格式化消息 ..........................................................................................................................113
配置本地化报表 ..................................................................................................................113
12 脚本 ........................................................................................................................................114
JRAbstractScriptlet 类 .......................................................................................................... 114
iReport 处理脚本 .................................................................................................................116
用脚本部署报表 ..................................................................................................................117
iReport 用户手册
机密 第 5 页 2010-2-5
5
13 模板 ........................................................................................................................................118
模版结构: ..........................................................................................................................118
使用通用模板 ......................................................................................................................120
14 图表 ........................................................................................................................................122
创建一个简单的图表 ..........................................................................................................122
级 Series................................................................................................................................127
自动级 ..........................................................................................................................128
手动级 ..........................................................................................................................129
图表类型和属性 ..................................................................................................................131
饼图 ..............................................................................................................................132
3D 饼图 ........................................................................................................................132
柱状图 ..........................................................................................................................133
3D 柱状图.....................................................................................................................135
线图 ..............................................................................................................................135
区域图 ..........................................................................................................................136
15 插件和附加工具 ....................................................................................................................136
插件结构 XML 文件............................................................................................................137
it.businesslogic.ireport.plugin.IReportPlugin 类 ..................................................................138
大型编译器插件 ..................................................................................................................141
文本向导插件 ......................................................................................................................143
16 常规问题解决方案 ................................................................................................................144
打印百分比 ..........................................................................................................................144
计算组的发生数 ..................................................................................................................145
分离 detail ............................................................................................................................147
插入一个页 ..........................................................................................................................148
交叉报表 ..............................................................................................................................151
使用多重连接找回数据 ......................................................................................................151
如何使用存储过程 ..............................................................................................................152
1 序言
什么是 iReport?
iReport是一个能够创建复杂报表的开源项目,并且它能调用JasperReports
库应用于任何一种java应用程序。本身是分布式的且由符合GNU通用公共许可的
百分之百纯java编写。
由于它丰富的图形界面,你能够很快的创建出任何一种你想要的报表。
iReport能够让我们提高技术方面的信心,比如它能降低学习JasperReports的
XML语法的难度,而且能够为熟练的技术人员节省大量的时间并能开发出非常精
细的报表。
这里将带给大家的虽然是0.4.1版本的,但是大部分的资源都是来自于0.2.0