Aimd's Blog

  博客园 :: 首页 :: 新随笔 ::  :: 订阅 订阅 :: 管理 ::
  29 随笔 :: 0 文章 :: 101 评论 :: 0 引用

注意:郁闷了好几天了,这个方法直接放到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文件了

posted on 2006-05-15 18:02 Aimd 阅读(1932) 评论(12) 编辑 收藏

评论

#1楼 2006-12-11 15:36 rucie[未注册用户]
为什么我作为application运行会出现错误呢?
Platform.startup( config );
IDesignEngineFactory factory = (IDesignEngineFactory) Platform
.createFactoryObject( IDesignEngineFactory.EXTENSION_DESIGN_ENGINE_FACTORY );
engine = factory.createDesignEngine( config );

报错??你知道原因吗?我在tomcat下部署运行是正确的
 回复 引用   

#2楼 2006-12-11 16:51 rucie[未注册用户]
Can't load the report engine
运行了你的程序,但是报上述的错误,我想是不是我的项目里面少了什么东西???
 回复 引用   

#3楼[楼主] 2006-12-19 13:11 Aimd      
@rucie
应该是dependences添加的不够
用这个方法吧
http://www.cnblogs.com/Aimd/archive/2006/05/15/400748.aspx
 回复 引用 查看   

#4楼 2008-05-09 09:25 fy_kenny      
report engine 不需要内置WEB服务器吗?如:tomcat
 回复 引用 查看   

#5楼 2008-05-21 15:06 fengboy[未注册用户]
请问能不能用你的方法实现调用birt自己的servlet,如frameset的格式来显示报表呢??
 回复 引用   

#6楼 2008-05-23 14:39 fy_kenny      
那默认的那些工具栏按钮怎么添加 ?谢谢
 回复 引用 查看   

#7楼[楼主] 2008-05-26 13:20 Aimd      
@fy_kenny
参考
http://www.cnblogs.com/Aimd/archive/2006/05/16/401151.html
 回复 引用 查看   

#8楼 2008-05-28 10:29 fy_kenny      
这个我知道的,就是报表文件的设计.

我问的是:怎么样添加,那个工具条:如:打印,导出功能等.

要是基于viewer的,我知道指定frameset就可以显示出工具条了.

但是,我用报表引擎,就只能看到报表结果,而没有工具条出现.

所以,我考虑自己写代码实现那些功能.

如果,有更方便的方法就可以有那个工具条就更加好了.

你明白了吗?
 回复 引用 查看   

#9楼 2008-05-28 10:29 fy_kenny      
上面那个连接的文章 貌似不是我想要的
 回复 引用 查看   

欢迎大家去安讯中国官方论坛http://www.actuatechina.com/index.php,提问与交流关于BIRT等安讯所有产品的问题,我们的工程师会在第一时间给您答复。
 回复 引用   

#11楼[楼主] 2008-06-04 10:42 Aimd      
@Brian.Chen
新成立的啊,不错,大家支持一下吧,birt是不错的产品
 回复 引用 查看   

呵呵,谢谢支持啊,希望大家多多交流,我们也会尽力给予帮助的
 回复 引用