新书推介:《语义网技术体系》
作者:瞿裕忠,胡伟,程龚
   XML论坛     W3CHINA.ORG讨论区     >>计算机科学论坛<<     SOAChina论坛     Blog     开放翻译计划     新浪微博  
 
  • 首页
  • 登录
  • 注册
  • 软件下载
  • 资料下载
  • 核心成员
  • 帮助
  •   Add to Google

    >> 本版讨论Java, J2SE, J2ME, J2EE, 以及Eclipse, NetBeans, JBuilder等Java开发环境,还有JSP, JavaServlet, JavaBean, EJB以及struts, hibernate, spring, webwork2, Java 3D, JOGL等相关技术。
    [返回] 计算机科学论坛计算机技术与应用『 Java/Eclipse 』 → [求助]如何调用birt制作的报表? 查看新帖用户列表

      发表一个新主题  发表一个新投票  回复主题  (订阅本版) 您是本帖的第 50251 个阅读者浏览上一篇主题  刷新本主题   平板显示贴子 浏览下一篇主题
     * 贴子主题: [求助]如何调用birt制作的报表? 举报  打印  推荐  IE收藏夹 
       本主题类别:     
     DMman 帅哥哟,离线,有人找我吗?魔羯座1984-1-11
      
      
      威望:1
      头衔:数据挖掘青年
      等级:研二(Pi-Calculus看得一头雾水)(版主)
      文章:803
      积分:5806
      门派:W3CHINA.ORG
      注册:2007/4/9

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给DMman发送一个短消息 把DMman加入好友 查看DMman的个人资料 搜索DMman在『 Java/Eclipse 』的所有贴子 点击这里发送电邮给DMman 访问DMman的主页 引用回复这个贴子 回复这个贴子 查看DMman的博客楼主
    发贴心情 [求助]如何调用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

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


       收藏   分享  
    顶(0)
      




    ----------------------------------------------
    数据挖掘青年 http://blogger.org.cn/blog/blog.asp?name=DMman
    纪录片之家 (很多纪录片下载)http://www.jlpzj.com/?fromuid=137653

    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2007/6/22 16:35:00
     
     GoogleAdSense魔羯座1984-1-11
      
      
      等级:大一新生
      文章:1
      积分:50
      门派:无门无派
      院校:未填写
      注册:2007-01-01
    给Google AdSense发送一个短消息 把Google AdSense加入好友 查看Google AdSense的个人资料 搜索Google AdSense在『 Java/Eclipse 』的所有贴子 点击这里发送电邮给Google AdSense 访问Google AdSense的主页 引用回复这个贴子 回复这个贴子 查看Google AdSense的博客广告
    2024/5/17 15:12:15

    本主题贴数11,分页: [1] [2]

     *树形目录 (最近20个回帖) 顶端 
    主题:  [求助]如何调用birt制作的报表?(3660字) - DMman,2007年6月22日
        回复:  楼主能给我也发一份么?谢谢~~liangzhijun4@163.com..(50字) - liangzhijun4,2012年10月10日
        回复:  楼主能给我也发一份么?谢谢~~liangzhijun4@163.com..(52字) - liangzhijun4,2012年10月10日
        回复:  军哥,我正在研发java程序,遇到报表打印无法解决。现在急等用。请您在百忙之中给我发一个实现在ja..(177字) - dcjyjzl,2012年9月26日
        回复:  军哥,请给我发一个实现在java GUI应用程序中,点击一个报表按钮,报表就出来的功能的例子吧..(118字) - pf_letitbe,2010年3月1日
        回复:  关于birt大家可以参考http://www.ieee.org.cn/dispbbs.asp?b..(160字) - DMman,2007年12月18日
        回复:  军哥,请也给我发一个小例子,实现在java GUI应用程序中,点击一个报表按钮,报表就出来的功能...(120字) - cjokok823@sohu.com,2007年11月29日
        回复:  多谢!(5字) - DMman,2007年6月29日
        回复:  @DMman,这两天太忙,过两天给你答复一下。(42字) - hongjunli,2007年6月23日
            回复:  [quote][b]以下是引用[i]hongjunli在2007-6-23 23:40:00[/i..(167字) - DMman,2007年6月24日
                回复:  [quote][b]以下是引用[i]DMman在2007-6-24 8:52:00[/i]的发言:..(287字) - hongjunli,2007年6月28日
                    回复:  军哥,请给我发一个实现在java GUI应用程序中,点击一个报表按钮,报表就出来的功能的例子吧!谢..(117字) - sunwansong,2008年4月14日

    W3C Contributing Supporter! W 3 C h i n a ( since 2003 ) 旗 下 站 点
    苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
    78.125ms