Notice: Undefined index: in /data/phpspider/phplib/misc.function.php on line 226
Java 以excel格式导出BIRT报告_Java - Fatal编程技术网

Java 以excel格式导出BIRT报告

Java 以excel格式导出BIRT报告,java,Java,如何使用java代码将BIRT报表直接导出到excel。 我无法连接到数据库。我打开了excel工作表,但没有从数据库中获取其中的内容 这是我的密码: public void openExcelReport() throws IOException, ServletException { String reportFile = "testreport.rptdesign"; IReportEngine birtReportEngine = null; EngineConfig c

如何使用java代码将BIRT报表直接导出到excel。 我无法连接到数据库。我打开了excel工作表,但没有从数据库中获取其中的内容

这是我的密码:

public void openExcelReport() throws IOException, ServletException {

  String reportFile = "testreport.rptdesign";

  IReportEngine birtReportEngine = null;
  EngineConfig conf = null;

  HttpServletResponse resp = ServletActionContext.getResponse();
  request = ServletActionContext.getRequest();
  resp.setContentType("application/vnd.ms-excel");
  String fileName = "BE-Mechanical-2010-11";
  resp.setHeader("Content-disposition", "attachment; filename=" + fileName);
  ServletContext sc = request.getSession().getServletContext();

  try {
    conf = new EngineConfig();
    conf.setEngineHome("ReportEngine");
    conf.setLogConfig(null, Level.FINE);
    IReportEngineFactory factory = (IReportEngineFactory) Platform
        .createFactoryObject(IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY);
    birtReportEngine = factory.createReportEngine(conf);

    IReportRunnable design = null;
    // Open report design
    design = birtReportEngine.openReportDesign(sc.getRealPath("/birt_files/"
        + reportFile));
    // create task to run and render report
    IRunAndRenderTask task = birtReportEngine.createRunAndRenderTask(design);

    // set output options
    HTMLRenderOption options = new HTMLRenderOption();
    options.setOutputFormat("html");

    options.setOutputStream(resp.getOutputStream());
    task.setRenderOption(options);
    // run report
    task.run();
    task.close();

  } catch (Exception e) {
    e.printStackTrace();
    throw new ServletException(e);
  }
}

我不知道这是否有帮助,但是。。 在这种情况下,您需要您的xml文件,这就是reportFileFullPath的含义,如果 xml显示记录时,也会在excel上看到记录

def reportFileFullPath = "${reportHome}${File.separator}${reportName}.rptdesign"

        if(File.separator.equals("/"))
            reportFileFullPath = reportFileFullPath.replace("\\", File.separator)
        else
            reportFileFullPath = reportFileFullPath.replace("/", File.separator)

        def IReportRunnable reportDesign = reportEngine.openReportDesign(reportFileFullPath)

这个代码对我有用

        // Open report design
        IReportRunnable design = 
        birtEngine.openReportDesign(sc.getRealPath("/report/") + reportName 
        + ".rptdesign");

        ReportDesignHandle report = (ReportDesignHandle) design.getDesignHandle();

        // create task to run and render report
        task = birtEngine.createRunAndRenderTask(design);

        res.setContentType("application/vnd.ms-excel");
        res.setHeader("Content-Disposition", "attachment; filename=\"" + 
                      "xcel.xls" + "\"");
        EXCELRenderOption options = new EXCELRenderOption();
        options.setOutputFormat("xlsx");
        res.setHeader("Content-Disposition", "inline; filename=report.xlsx");

        options.setOutputFileName("corporate-batches-summary-report.xlsx");
        options.setOutputStream(res.getOutputStream());
        task.setRenderOption(options);
        task.run();
        task.close();

是否要生成Excel文件?在这种情况下,为什么要设置HTMLRenderOption?