iReport 笔记(七) 为子报表添加统计信息

来源:互联网 发布:分光计实验数据 编辑:程序博客网 时间:2024/05/04 10:34
p {font-family: "宋体";font-size: 12px;font-style: normal;line-height: 18px;font-weight: normal;text-indent: 24px;}h1 {font-size: 36px;font-style: normal;font-weight: bold;text-decoration: underline;color: #990000;text-align: center;}h2 {font-size: 24px;font-weight: bold;color: #9900FF;}h3 {font-size: 18px;font-weight: bold;color: #000099;}a {color: #660033;text-decoration: none;}img {vertical-align: middle;}ul {font-family: "宋体";font-size: 12px;line-height: 18px;}PRE { font-size: 12px; padding: 5px; border-style: solid; border-width: 1px; border-color: #CCCCCC; background-color: #F0F0F0;}table {font-size: 12px;border-collapse: collapse;}tr {background-color: inherit;color: black;padding: 5px;text-align: left;border: 1px solid #999999;}th {text-align: center;background-color: #cccccc;color: black;font-weight: bolder;padding: 5px;border: 1px solid #999999;}td {border: 1px solid #999999;padding: 5px;}ol {font-family: "宋体";font-size: 12px;line-height: 18px;}h4 {font-size: 16px;}

为子报表添加统计信息

内容与上例基本相同,但在子报表中添加一些统计信息,最后结果如下图所示:

程序部分

首先,我修改一下ProvinceBean的定义,添加一个只读属性cityCount,如下代码中的阴影部分所示:

package lld.test.ireport;import java.util.ArrayList;public class ProvinceBean{private String provinceName;private ArrayList<CityBean> cities;public int getCityCount(){if(this.cities != null)return this.cities.size();elsereturn 0;}public String getProvinceName(){return provinceName;}public void setProvinceName(String provinceName){this.provinceName = provinceName;}public ArrayList<CityBean> getCities(){return cities;}public void setCities(ArrayList<CityBean> cities){this.cities = cities;}}

其余代码不作修改

报表部分

在主报表的“Java Bean Data Source”中,引入新添加的cityCount字段。

在主报表的子报表控件上,打开其属性窗口,添加“CITY_COUNT”参数,如下图所示:

打开子报表,添加参数“CITY_COUNT”(添加参数的方式为在左下角“Document structure”工具窗口的Parameters节点添加),如下图所示:

然后,修改子报表设计,添加summay栏(可通过右右键),如下图所示:

OK,本例至此完成。

注: 如需本例示例代码, 请留言

 

原创粉丝点击