【2018年整理】BIRT与WEB整合生成动态表

上传人:ji****72 文档编号:28662241 上传时间:2018-01-19 格式:DOC 页数:5 大小:52.50KB
返回 下载 相关 举报
【2018年整理】BIRT与WEB整合生成动态表_第1页
第1页 / 共5页
【2018年整理】BIRT与WEB整合生成动态表_第2页
第2页 / 共5页
【2018年整理】BIRT与WEB整合生成动态表_第3页
第3页 / 共5页
【2018年整理】BIRT与WEB整合生成动态表_第4页
第4页 / 共5页
【2018年整理】BIRT与WEB整合生成动态表_第5页
第5页 / 共5页
亲,该文档总共5页,全部预览完了,如果喜欢就下载吧!
资源描述

《【2018年整理】BIRT与WEB整合生成动态表》由会员分享,可在线阅读,更多相关《【2018年整理】BIRT与WEB整合生成动态表(5页珍藏版)》请在金锄头文库上搜索。

1、BIRT 与 WEB 整合生成动态表有时候生成报表时,表的属性列不固定,这个时候用传统的 BIRT 构建表满足不了要求,我们可以通过 BIRT 整合 WEB 来生成动态表。具体方法如下:1、 建立数据源和数据集新建一个 “Scripted Data Source”的数据源(以“PieDataSource”命名为例) ;从PieDataSource 数据源中新建一个 Scripted Data Set 数据集(以 “PieDataSet”命名为例) 。2、 建立一个空的 Table 项新建一个 1 行 1 列的 Table (Table 以 “PieTable” 命名为例) ,拖入适当的布局区域

2、,并绑定一个 数据集 PieDataSet 。3、 在 BIRT 设计页面中绑定 JAVA 类1) 在数据集 PieDataSet 的 Event Handler 中绑定一个实现 IScriptedDataSetEventHandler 接口(或继承 ScriptedDataSetEventHandler 类)的自定义类(以“PieChartDataSetEventHandle”命名为例)。2) 点击 BIRT 的报表设计工具的 layout 页面的空白处,在 Property Editor 的 Event Handler 标签中绑定一个继承 ReportEventAdapter 类(或实现

3、IReportEventAdapter 接口)的自定义类(以 “PieChartReportEventHandle”命名为例)。4、 代码编写1) 数据集的绑定类 PieChartDataSetEventHandle 代码如下:public class PieChartDataSetEventHandle implements IScriptedDataSetEventHandler /列属性数据(即表头数据)protected IColumnMetaData meta = null;/表头数量(即数据表中有多少列属性)protected int metaCount = 0;protected

4、 Iterator ite = null;/表头数据列表protected List metalist = new ArrayList();/数据键值对列表protected List pojolist = new ArrayList();/存放 ResultVOprotected Map hash = new HashMap();public void close(IDataSetInstance arg0) throws ScriptException meta = null;ite = null;SuppressWarnings(unchecked)public boolean desc

5、ribe(IDataSetInstance arg0, IScriptedDataSetMetaData arg1)throws ScriptException metalist.clear();metalist = (List) hash.get(metadata);pojolist = (List) hash.get(result);Iterator iterator = metalist.iterator();while(iterator.hasNext()arg1.addColumn(iterator.next(), String.class);return true;public b

6、oolean fetch(IDataSetInstance arg0, IUpdatableDataSetRow arg1)throws ScriptException if (ite = null | !ite.hasNext() return false; else try Map colmap = ite.next();for (int t = 0; t ) arg1.getParameterValue(resultvo);public void onFetch(IDataSetInstance arg0, IDataSetRow arg1,IReportContext arg2) th

7、rows ScriptException 2) PieChartReportEventHandle 中的 beforeFactory 方法代码:try ElementFactory elementFactory = reportContext.getDesignHandle().getElementFactory();/获取 Table 的句柄TableHandle mytable = (TableHandle) reportContext.getDesignHandle().findElement(PieTable);/设置 Table 的宽度mytable.setWidth(100%);P

8、ropertyHandle colbinds = mytable.getColumnBindings( );/取列表头文件PieResultDao dao=new PieResultDao();Map hash=dao.getResultMap();reportContext.setParameterValue(resultvo, hash);if(hash!= null&hash.get(metadata)!=null)List list=(List)hash.get(metadata);RowHandle myheader = (RowHandle) mytable.getHeader(

9、).get( 0 );/获得表格头RowHandle mydetail = (RowHandle) mytable.getDetail().get(0);/获得明细行int i=0;/计列数for(String column : list)/添加数据绑定列ComputedColumn cs = StructureFactory.createComputedColumn( );cs.setName( column );cs.setExpression( dataSetRow+column+);colbinds.addItem( cs );mytable.insertColumn(i,1);/循环

10、插入新列,每次加在最后一列的后面/ColumnHandle mycolumn = (ColumnHandle) mytable.getColumns().get(i); 可以得到表的列添加属性/mycolumn.setProperty(width, 2cm);/数据列CellHandle dcell = (CellHandle) mydetail.getCells().get(i);/取得明细行单元格/设置数据列样式dcell.setProperty(borderBottomColor,#000000);dcell.setProperty(borderBottomStyle,solid);dc

11、ell.setProperty(borderBottomWidth,1px);dcell.setProperty(borderLeftColor,#000000);dcell.setProperty(borderLeftStyle,solid);dcell.setProperty(borderLeftWidth,1px);dcell.setProperty(borderRightColor,#000000);dcell.setProperty(borderRightStyle,solid);dcell.setProperty(borderRightWidth,1px);dcell.setPro

12、perty(borderTopColor,#000000);dcell.setProperty(borderTopStyle,solid);dcell.setProperty(borderTopWidth,1px);DataItemHandle data = elementFactory.newDataItem(column);data.setResultSetColumn( (String)list.get(i);dcell.getContent().add(data);/为单元格设置Data/列头文件CellHandle hcell = (CellHandle) myheader.getC

13、ells( ).get(i);/设置列头样式hcell.setProperty(backgroundColor,#d0d0d0);hcell.setProperty(borderBottomColor,#000000);hcell.setProperty(borderBottomStyle,solid);hcell.setProperty(borderBottomWidth,1px);hcell.setProperty(borderLeftColor,#000000);hcell.setProperty(borderLeftStyle,solid);hcell.setProperty(bord

14、erLeftWidth,1px);hcell.setProperty(borderRightColor,#000000);hcell.setProperty(borderRightStyle,solid);hcell.setProperty(borderRightWidth,1px);hcell.setProperty(borderTopColor,#000000);hcell.setProperty(borderTopStyle,solid);hcell.setProperty(borderTopWidth,1px);LabelHandle myLabel = elementFactory.newLabel(column);myLabel.setText(column);hcell.getContent().add(myLabel);i+; catch (Exception e) e.printStackTrace();

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 生活休闲 > 综合/其它

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号