在plugin中用engine api引入BIRT已经设计好的rptdesign文件

注意:郁闷了好几天了,这个方法直接放到rcp下运行不了,几天过去才发现是个多么愚蠢的错误:在plugin.xml的dependiences添加org.eclipse.birt.report.viewer, org.eclipse.birt.core, org.eclipse.birt.report.engine, org.eclipse.birt.report.model等你需要的所有包后记得在自己的run--->configure-->plug-ins 里面把所有的birt都打上勾,否则运行会出错的

 

1,用birt设计rptdesign文件

(1)下载 birt framwork plugin放到eclipse目录下

(2)创建一个报表工程并制作一个报表(即rptdesign文件)

2,安装birt engine

下载 birt runtime 到任意目录,

3,创建一个java project 设置build 属性,使之包含birt 的core和report.engine,并把Report engine目录下的jar加到jar属性中

工程代码如下,其中几个路径根据自己配置设置:

import  java.util.HashMap;

import  org.eclipse.birt.report.engine.api.EngineConfig;
import  org.eclipse.birt.report.engine.api.EngineConstants;
import  org.eclipse.birt.report.engine.api.EngineException;
import  org.eclipse.birt.report.engine.api.HTMLRenderContext;
import  org.eclipse.birt.report.engine.api.HTMLRenderOption;
import  org.eclipse.birt.report.engine.api.IReportRunnable;
import  org.eclipse.birt.report.engine.api.IRunAndRenderTask;
import  org.eclipse.birt.report.engine.api.ReportEngine;

public   class  ExecuteReport {

 
static   void  executeReport()  throws  EngineException
 {
  
// Engine Configuration - set and get temp dir, BIRT home, Servlet context
  EngineConfig config  =   new  EngineConfig();
  config.setEngineHome( 
" C:/birtruntime/birt-runtime-2_0_0/Report Engine "  ); 
        
  
// Create the report engine
  ReportEngine engine  =   new  ReportEngine( config );
  
  
  
// Open a report design - use design to modify design, retrieve embedded images etc. 
  IReportRunnable design  =  engine.openReportDesign( " D:/LiuYanbin/working/TestBIRT/customers.rptdesign " ); 
  
  
// Create task to run the report - use the task to execute and run the report,
  IRunAndRenderTask task  =  engine.createRunAndRenderTask(design); 
  
  
// Set Render context to handle url and image locataions
  HTMLRenderContext renderContext  =   new  HTMLRenderContext();
  renderContext.setImageDirectory(
" image " );
  HashMap contextMap 
=   new  HashMap();
  contextMap.put( EngineConstants.APPCONTEXT_HTML_RENDER_CONTEXT, renderContext );
  task.setAppContext( contextMap );
  
  
// Set rendering options - such as file or stream output, 
  
// output format, whether it is embeddable, etc
  HTMLRenderOption options  =   new  HTMLRenderOption();
  options.setOutputFileName(
" D:/LiuYanbin/working/TestBIRT/customers.html " );
  options.setOutputFormat(
" html " );
  task.setRenderOption(options);
  
  
// run the report and destroy the engine
  task.run();
  
  engine.destroy();
 } 
 
/**
  * 
@param  args
  
*/
 
public   static   void  main(String[] args) {
  
try
  {
   executeReport( );
  }
  
catch  ( Exception e )
  {
   e.printStackTrace();
  }
 }

}



然后运行就可以看到生成的html文件了

转载于:https://www.cnblogs.com/Aimd/archive/2006/05/15/400747.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值