以文本方式查看主题

-  W3CHINA.ORG讨论区 - 语义网·描述逻辑·本体·RDF·OWL  (http://bbs.xml.org.cn/index.asp)
--  『 Java/Eclipse 』  (http://bbs.xml.org.cn/list.asp?boardid=41)
----  [求助]如何调用birt制作的报表?  (http://bbs.xml.org.cn/dispbbs.asp?boardid=41&rootid=&id=48902)


--  作者:DMman
--  发布时间:6/22/2007 4:35:00 PM

--  [求助]如何调用birt制作的报表?
以前用过Delphi和Grid++Report,进行了比较简单的报表,比如一个窗体上 有查询数据库的结果,然后 点击“打印”,则 出现一张报表,可以预览、保存、打印设置、打印等。
    现在使用java,用birt设计了一张报表(.rptdesign),但是不知道怎样把它和应用程序关联。

   在网上搜到的关于Birt使用的例子多是 如何制作报表,没有关联应用程序这一块。

   找到了一个例子:

在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文件了




然后我按照操作:
1、在java工程的属性里引入了eclipse\plugins下所有的有关于birt的jar
2、安装了birt-runtime
3、修改了程序中的相关路径设置
运行时出现 Can't load the report engine

怎样才能实现在应用程序中调用报表呢?也就是说 点击“打印”,报表就出来了?
版主能给个小例子看吗?多谢了!



--  作者:hongjunli
--  发布时间:6/23/2007 11:40:00 PM

--  
@DMman,这两天太忙,过两天给你答复一下。

--  作者:DMman
--  发布时间:6/24/2007 8:52:00 AM

--  
以下是引用hongjunli在2007-6-23 23:40:00的发言:
@DMman,这两天太忙,过两天给你答复一下。



多谢军哥,不必着急。我暂时还用不到,您忙先
--  作者:hongjunli
--  发布时间:6/28/2007 10:14:00 PM

--  
以下是引用DMman在2007-6-24 8:52:00的发言:
[quote]以下是引用hongjunli在2007-6-23 23:40:00的发言:
@DMman,这两天太忙,过两天给你答复一下。
  
[/quote]
多谢军哥,不必着急。我暂时还用不到,您忙先

我给你发email了,请注意查收你的邮件。


--  作者:DMman
--  发布时间:6/29/2007 9:11:00 AM

--  
多谢!
--  作者:cjokok823@sohu.com
--  发布时间:11/29/2007 8:34:00 PM

--  
军哥,请也给我发一个小例子,实现在java GUI应用程序中,点击一个报表按钮,报表就出来的功能.万分感谢.
cjokok823@sohu.com
--  作者:DMman
--  发布时间:12/18/2007 6:32:00 PM

--  
关于birt大家可以参考
http://www.ieee.org.cn/dispbbs.asp?boardID=41&ID=48328

我最近使用jasper发现比birt方便多了,如果用过Grid++Report的朋友会发现他们有些相似


--  作者:sunwansong
--  发布时间:4/14/2008 4:34:00 PM

--  
军哥,请给我发一个实现在java GUI应用程序中,点击一个报表按钮,报表就出来的功能的例子吧!谢谢~~
sunwansong110@126.com
--  作者:pf_letitbe
--  发布时间:3/1/2010 9:25:00 AM

--  

军哥,请给我发一个实现在java GUI应用程序中,点击一个报表按钮,报表就出来的功能的例子吧!谢谢~~
pf_letitbe@163.com


--  作者:dcjyjzl
--  发布时间:9/26/2012 9:28:00 PM

--  
军哥,我正在研发java程序,遇到报表打印无法解决。现在急等用。请您在百忙之中给我发一个实现在java GUI应用程序中,点击一个报表按钮,报表就出来的功能的例子吧!谢谢~~
dcjyjzl@126.com
--  作者:liangzhijun4
--  发布时间:10/10/2012 7:40:00 PM

--  
楼主能给我也发一份么?谢谢~~
liangzhijun4@163.com

--  作者:liangzhijun4
--  发布时间:10/10/2012 7:52:00 PM

--  
楼主能给我也发一份么?谢谢~~
liangzhijun4@163.com
W 3 C h i n a ( since 2003 ) 旗 下 站 点
苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
273.438ms