百灵报表(BIRT)接口学习:设计report design
来源:互联网 发布:jsp连接sql的方法 编辑:程序博客网 时间:2024/04/30 07:59
第一步,初始化ReportDesignHandle和ElementFactory的对象,前者代表生成的report design;后者用来创建所用到的报表元素。
IDesignEngine designEngine = new DesignEngine( new DesignConfig( ) );
ReportDesignHandle reportDesignHandle = designEngine.newSessionHandle(
ULocale.ENGLISH ).createDesign( );
ElementFactory elementFactory = new ElementFactory( reportDesignHandle
.getModule( ) );
第二步,创建Parameter。
ScalarParameterHandle scalarParameterHandle = elementFactory
.newScalarParameter( "param" );
scalarParameterHandle.setIsRequired( false );
scalarParameterHandle.setDefaultValue( "
reportDesignHandle.getParameters( ).add( scalarParameterHandle );
第三步,创建Data Source。
OdaDataSourceHandle dataSourceHandle = elementFactory.newOdaDataSource(
"data source",
"org.eclipse.birt.report.data.oda.jdbc" );
dataSourceHandle.setProperty(
"odaDriverClass",
"org.eclipse.birt.report.data.oda.sampledb.Driver" );
dataSourceHandle.setProperty( "odaURL", "jdbc:classicmodels:sampledb" );
dataSourceHandle.setProperty( "odaUser", "ClassicModels" );
// dataSourceHandle.setProperty( "odaPassword", "ClassicModels" );
reportDesignHandle.getDataSources( ).add( dataSourceHandle );
第四步,创建Data Set。
OdaDataSetHandle dataSetHandle = elementFactory.newOdaDataSet(
"data set",
"org.eclipse.birt.report.data.oda.jdbc.JdbcSelectDataSet" );
dataSetHandle.setDataSource( dataSourceHandle.getName( ) );
dataSetHandle.setQueryText( "select * from CLASSICMODELS.CUSTOMERS" );
FilterCondition filterCondition = StructureFactory.createFilterCond( );
filterCondition.setOperator( DesignChoiceConstants.FILTER_OPERATOR_EQ );
filterCondition.setExpr( "row[/"COUNTRY/"]" );
filterCondition.setValue1( "params[/""
+ scalarParameterHandle.getName( ) + "/"].value" );
dataSetHandle.addFilter( filterCondition );
reportDesignHandle.getDataSets( ).add( dataSetHandle );
第五步,创建Sytle。
SharedStyleHandle sharedStyleHandle = elementFactory.newStyle( null );
ColorHandle colorHandle = sharedStyleHandle.getColor( );
colorHandle.setStringValue( "red" );
reportDesignHandle.getStyles( ).add( sharedStyleHandle );
第六步,创建Table。
TableHandle tableHandle = elementFactory.newTableItem(
"table",
3,
1,
1,
1 );
tableHandle.setProperty(
StyleHandle.BORDER_TOP_STYLE_PROP,
DesignChoiceConstants.LINE_STYLE_SOLID );
tableHandle.setProperty(
StyleHandle.BORDER_LEFT_STYLE_PROP,
DesignChoiceConstants.LINE_STYLE_SOLID );
tableHandle.setProperty(
StyleHandle.BORDER_BOTTOM_STYLE_PROP,
DesignChoiceConstants.LINE_STYLE_SOLID );
tableHandle.setProperty(
StyleHandle.BORDER_RIGHT_STYLE_PROP,
DesignChoiceConstants.LINE_STYLE_SOLID );
tableHandle.setDataSet( dataSetHandle );
ComputedColumn computedColumn1 = StructureFactory
.createComputedColumn( );
computedColumn1.setName( "CustomerNumber" );
computedColumn1.setDisplayName( "CustomerNumber" );
computedColumn1.setDataType(
DesignChoiceConstants.COLUMN_DATA_TYPE_INTEGER );
computedColumn1.setExpression( "dataSetRow[/"CUSTOMERNUMBER/"]" );
tableHandle.addColumnBinding( computedColumn1, false );
ComputedColumn computedColumn2 = StructureFactory
.createComputedColumn( );
computedColumn2.setName( "CustomerName" );
computedColumn2.setDisplayName( "CustomerName" );
computedColumn2.setDataType(
DesignChoiceConstants.COLUMN_DATA_TYPE_STRING );
computedColumn2.setExpression( "dataSetRow[/"CUSTOMERNAME/"]" );
tableHandle.addColumnBinding( computedColumn2, false );
ComputedColumn computedColumn3 = StructureFactory
.createComputedColumn( );
computedColumn3.setName( "Country" );
computedColumn3.setDisplayName( "Country" );
computedColumn3.setDataType(
DesignChoiceConstants.COLUMN_DATA_TYPE_STRING );
computedColumn3.setExpression( "dataSetRow[/"COUNTRY/"]" );
tableHandle.addColumnBinding( computedColumn3, false );
ComputedColumn computedColumn4 = StructureFactory
.createComputedColumn( );
computedColumn4.setName( "Total Count" );
computedColumn4.setDisplayName( "Total Count" );
computedColumn4.setAggregateFunction( "COUNT" );
computedColumn4.setDataType(
DesignChoiceConstants.COLUMN_DATA_TYPE_INTEGER );
computedColumn4.setExpression( "row[/"CustomerNumber/"]" );
tableHandle.addColumnBinding( computedColumn4, false );
RowHandle headerRowHandle = (RowHandle) tableHandle
.getHeader( )
.get( 0 );
headerRowHandle.setProperty(
StyleHandle.TEXT_ALIGN_PROP,
DesignChoiceConstants.TEXT_ALIGN_LEFT );
CellHandle headerCellHandle1 = (CellHandle) headerRowHandle
.getCells( )
.get( 0 );
LabelHandle labelHandle1 = elementFactory.newLabel( "CustomerNumber" );
labelHandle1.setText( "CustomerNumber" );
headerCellHandle1.getContent( ).add( labelHandle1 );
CellHandle headerCellHandle2 = (CellHandle) headerRowHandle
.getCells( )
.get( 1 );
LabelHandle labelHandle2 = elementFactory.newLabel( "CustomerName" );
labelHandle2.setText( "CustomerName" );
headerCellHandle2.getContent( ).add( labelHandle2 );
CellHandle headerCellHandle3 = (CellHandle) headerRowHandle
.getCells( )
.get( 2 );
LabelHandle labelHandle3 = elementFactory.newLabel( "Country" );
labelHandle3.setText( "Country" );
headerCellHandle3.getContent( ).add( labelHandle3 );
RowHandle detailRowHandle = (RowHandle) tableHandle
.getDetail( )
.get( 0 );
CellHandle detailCellHandle1 = (CellHandle) detailRowHandle
.getCells( )
.get( 0 );
DataItemHandle dataItemHandle1 = elementFactory
.newDataItem( "CustomerNumber" );
dataItemHandle1.setResultSetColumn( computedColumn1.getName( ) );
detailCellHandle1.getContent( ).add( dataItemHandle1 );
CellHandle detailCellHandle2 = (CellHandle) detailRowHandle
.getCells( )
.get( 1 );
DataItemHandle dataItemHandle2 = elementFactory
.newDataItem( "CustomerName" );
dataItemHandle2.setResultSetColumn( computedColumn2.getName( ) );
detailCellHandle2.getContent( ).add( dataItemHandle2 );
CellHandle detailCellHandle3 = (CellHandle) detailRowHandle
.getCells( )
.get( 2 );
DataItemHandle dataItemHandle3 =
elementFactory.newDataItem( "Country" );
dataItemHandle3.setResultSetColumn( computedColumn3.getName( ) );
detailCellHandle3.getContent( ).add( dataItemHandle3 );
RowHandle footerRowHandle = (RowHandle) tableHandle
.getFooter( )
.get( 0 );
CellHandle footerCellHandle1 = (CellHandle) footerRowHandle
.getCells( )
.get( 0 );
LabelHandle labelHandle4 = elementFactory.newLabel( "Total Count" );
labelHandle4.setText( "Total Count" );
footerCellHandle1.getContent( ).add( labelHandle4 );
CellHandle footerCellHandle2 = (CellHandle) footerRowHandle
.getCells( )
.get( 1 );
DataItemHandle dataItemHandle4 = elementFactory
.newDataItem( "Total Count" );
dataItemHandle4.setResultSetColumn( computedColumn4.getName( ) );
footerCellHandle2.getContent( ).add( dataItemHandle4 );
tableHandle.setStyle( sharedStyleHandle );
reportDesignHandle.getBody( ).add( tableHandle );
第七步,输出report design。
ModuleHandle moduleHandle = reportDesignHandle.getModuleHandle( );
moduleHandle.saveAs( getOutputFolder( ) + File.separator + report );
reportDesignHandle.close( );
在Web Viewer中预览生成的报表应该可以得到这样的输出:
CustomerNumber
CustomerName
Country
114
Australian Collectors, Co.
276
Anna's Decorations, Ltd
282
Souveniers And Things Co.
333
Australian Gift Network, Co
471
Australian Collectables, Ltd
Total Count
5
- 百灵报表(BIRT)接口学习:设计report design
- 百灵报表(BIRT)接口学习:执行Cube Query
- 百灵报表(BIRT)接口学习:使用Data Extraction Task导出数据
- 百灵报表(BIRT)中文网站
- 百灵报表(BIRT)中的样例
- 报表Birt report
- birt报表报错, There is no report design object available.org.eclipse.birt.report.exception.ViewerExcepti
- birt 报表 design
- BIRT 报表 RCP Report Viewer
- 百灵报表(birt)的体系结构和功能简介
- 百灵报表(Eclipse BIRT)中的边框样式
- 优秀的开源报表工具BIRT(百灵)介绍
- birt百灵报表与web项目集成示例和源码
- BIRT Design API 学习
- BIRT报表开发学习
- birt报表学习
- 在Eclipse中用Java实现百灵报表(BIRT)的事件处理
- BIRT设计报表运行时的问题——invalid design file file:....
- IBM WebSphere 开发者技术期刊第 60 期
- 转:Paypal ipn
- 转:paypal express checkout
- 使用 IBM Data Studio 为 WAS 创建和部署 Data Web Services
- DbgridToExcell
- 百灵报表(BIRT)接口学习:设计report design
- 程序员的爱情表白
- 在TListBox和TComboBox中绘图
- 水晶报表中显示动态图片
- 《Linux命令行和Shell脚本开发圣经》:内容速览
- 高效率创建安全的 Java 应用,第 2 部分
- 定制MOSS列表编辑页面
- reportViewer1报表打印
- [OpenSolaris][kernel]Solaris内核加载设备驱动过程