第一步,初始化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( "Australia" );
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.
|
Australia
|
276
|
Anna's Decorations, Ltd
|
Australia
|
282
|
Souveniers And Things Co.
|
Australia
|
333
|
Australian Gift Network, Co
|
Australia
|
471
|
Australian Collectables, Ltd
|
Australia
|
Total Count
|
5
|
|
分享到:
相关推荐
二、BIRT报表API的使用步骤 1. **初始化引擎**:首先,我们需要初始化BIRT引擎,这通常涉及到设置工作区和加载必要的插件。 ```java Platform.startup(new NullProgressMonitor()); IReportEngineFactory factory = ...
在开发BIRT报表时,理解和掌握其官方API至关重要,因为这将直接影响到报表的设计、数据处理以及功能实现。 首先,我们要理解BIRT API的核心组成部分: 1. **Report Designer API**:这是BIRT的图形化报告设计界面...
6. **实例分析**:压缩包中的"birt报表实例2"可能包含了一个或多个具体的代码示例,演示了如何使用BIRT API创建和运行报表。这些实例可能会覆盖从数据源创建、报表设计、数据填充到最终的报表渲染全过程。 通过学习...
4. **参数传递**:BIRT报表支持参数,API允许你在运行时设置参数值。这在动态生成报表或者根据用户输入调整报表内容时非常有用。 5. **自定义渲染和扩展**:如果你需要更复杂的渲染效果或者自定义行为,可以通过...
**BIRT报表使用总结** BIRT(Business Intelligence and Reporting Tools)是开源的Java报表系统,由Eclipse基金会维护,广泛应用于各类企业的数据可视化和报告生成。本总结将详细介绍BIRT的配置、使用环境以及如何...
综上所述,BIRT 报表工具是一款功能强大、易于使用的报表生成工具,它不仅能满足企业日常的数据处理需求,还能适应未来技术发展趋势。无论是初学者还是高级用户,都可以从 BIRT 中找到满足自己需求的功能。
构建Birt报表应用程序涉及到多个步骤和技术要点,这里将详细解释Birt报表引擎的基本概念、安装过程以及初步使用方法。 Birt全称为Business Intelligence and Reporting Tools,是一个由Eclipse基金会维护的开源报表...
主要根据BIRT API来动态生成报表的pdf,word等格式,导出到某一目录,希望对做birt报表的朋友有用。
《BIRT 中文指南.pdf》是一本全面介绍BIRT的中文指南,涵盖了BIRT的安装、设计环境(BIRT Designer)的使用、报表的创建和发布、数据集和数据源的管理等方面。这本指南可能还包括了一些示例和实战教程,帮助初学者...
【Birt报表的开发使用手册】 Birt报表是一款开源的报表系统,由Eclipse基金会维护,主要用于生成复杂的业务报告和数据分析。它集成了强大的图表、数据处理和样式设计功能,适用于Java环境,广泛应用于企业级应用...
Birt报表开发是一种基于开源Java平台的报表系统,它由Eclipse基金会维护,广泛应用于企业级的数据可视化和报告生成。这个资料集合包含了多种资源,对于初学者和有经验的开发者来说,都是宝贵的参考资料。 首先,...
它们是BIRT官方提供的帮助文档,包含详细的API参考、示例代码和教程,可以帮助开发者快速理解和使用Birt API及Birt Chart API。 总的来说,掌握Birt API和Birt Chart API对于进行基于BIRT的项目开发至关重要。通过...
6.1 **学习资料**:网上有许多教程、论坛和官方文档,帮助开发者学习Birt的基本概念、设计技巧和API使用。 6.2 **缺点**:虽然Birt功能强大,但学习曲线较陡,对新手来说可能需要一定时间适应;另外,对于大型复杂...
本资源包包含BIRT的中文和英文文档,API参考以及各种使用小技巧报表实例,非常适合想要深入学习BIRT的人士。 **中文与英文文档**: - **中文文档**:对于初学者来说,中文文档能够帮助更好地理解BIRT的各个方面,...
7. **Web Viewer API**:用于在Web应用程序中嵌入BIRT报表查看器。开发者可以利用此API控制报表的显示和交互行为。 通过深入学习BIRT API,开发者可以实现以下目标: - 自定义数据源和连接,以适应特定的数据存储...
Birt报表开发文档是一套全面的资源集合,适合Birt初学者及有经验的开发者进行学习和提升。这个压缩包包含各种格式的资料,如CHM(编译过的HTML帮助文件)、PDF和DOC文档,提供了丰富的信息来了解和掌握Birt报表系统...
通过以上步骤,你可以成功地在Java EE项目中集成BIRT报表。这个过程涉及到Java编程、Web应用开发、报表设计和服务器端集成等多个方面,需要对整个系统有深入的理解。在实际操作中,可能会遇到一些特定的问题,例如...
### BIRT报表部署详解 #### 一、BIRT概述与安装 **BIRT** (Business Intelligence and Reporting Tools) 是一个基于Eclipse平台的开源报表系统,主要为Java和J2EE应用程序提供报表设计和集成的功能。它不仅提供了...
构建一个BIRT报表应用程序涉及到多个步骤,主要包括创建和配置报表引擎、打开报表文档、连接数据源、设置报表生成选项、生成报表以及可选任务。以下是对这些知识点的详细解释: 1. **创建和配置报表引擎**: BIRT...
- 使用该API库,可以在Web页面中无缝嵌入完整的BIRT报表或单个报表元素。 - 库文件位置:`$Actuate_Home\iServer\servletcontainer\iportal\iportal\jsapi` 2. **适用环境** - 安讯信息控制台 (Actuate ...