首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 企业软件 > 行业软件 >

怎么用代码导出报表

2012-08-21 
如何用代码导出报表?1.创建报表引擎2.创建设计处理器reportRunnable reportEngine.openReportDesign(fil

如何用代码导出报表?
1.创建报表引擎
  2.创建设计处理器

   reportRunnable = reportEngine.openReportDesign(filePath);  designHandle = (ReportDesignHandle) reportRunnable.getDesignHandle( ); 

                  3.导出
IRunAndRenderTask task = reportEngine.createRunAndRenderTask(reportRunnable);
a.html  
 
                     HTMLServerImageHandler imageHandler = new HTMLServerImageHandler();HTMLRenderOption option = new HTMLRenderOption();option.setOutputFileName(savePath+"/"+fileName); option.setImageHandler(imageHandler); option.setActionHandler(new HTMLActionHandler());option.setOutputFormat("html");  HTMLRenderContext renderContext = new HTMLRenderContext();renderContext.SetRenderOption(option);renderContext.setSupportedImageFormats("JPG;PNG;BMP;SVG");String imgPath = fileName.substring(0,fileName.indexOf(".")); renderContext.setImageDirectory(savePath+"/"+imgPath+".files");renderContext.setBaseImageURL("./"+imgPath+".files");HashMap<Object, Object> contextMap = new HashMap<Object, Object>();contextMap.put( EngineConstants.APPCONTEXT_HTML_RENDER_CONTEXT, renderContext );task.setAppContext(contextMap);option.setEmbeddable(true);task.setRenderOption(option); task.run();  

  b.pdf        
  
          PDFRenderContext renderContext = new PDFRenderContext();renderContext.setBaseURL(""); HashMap<Object, Object> contextMap = new HashMap<Object, Object>();contextMap.put(EngineConstants.APPCONTEXT_PDF_RENDER_CONTEXT,renderContext);task.setAppContext(contextMap);RenderOptionBase options = new RenderOptionBase(); options.setOutputFileName(savePath+"/"+fileName); options.setOutputFormat("pdf"); options.setActionHandler(new HTMLActionHandler());task.setRenderOption(options);task.run();  

  c.xls   
              
    Map<Object, Object> xlsMap = new HashMap<Object, Object>();xlsMap.put("fixed_column_width", Integer.valueOf(30));xlsMap.put("show_grid_lines", Boolean.valueOf(false));engineConfig.setEmitterConfiguration("xls", xlsMap);RenderOptionBase options = new RenderOptionBase();options.setOutputFormat("xls");options.setOutputFileName(filePath);EXCELRenderOption excelOptions = new EXCELRenderOption(options);excelOptions.setSupportedImageFormats("JPG;PNG;BMP;SVG");HTMLServerImageHandler imageHandler = new HTMLServerImageHandler();excelOptions.setImageHandler(imageHandler);task.setRenderOption(excelOptions);  

  4.关闭任务
  task.close();
  5.关闭报表
reportEngine.shutdown();
 Platform.shutdown();

热点排行