[b]1.创建报表引擎[/b]
[b]2.创建设计处理器[/b]
[b]3.导出[/b]
IRunAndRenderTask task = reportEngine.createRunAndRenderTask(reportRunnable);
[b] a.html[/b]
[b]b.pdf[/b]
[b]c.xls[/b]
[b]4.关闭任务[/b]
task.close();
[b]5.关闭报表[/b]
reportEngine.shutdown();
Platform.shutdown();
[b]2.创建设计处理器[/b]
reportRunnable = reportEngine.openReportDesign(filePath);
designHandle = (ReportDesignHandle) reportRunnable.getDesignHandle( );
[b]3.导出[/b]
IRunAndRenderTask task = reportEngine.createRunAndRenderTask(reportRunnable);
[b] a.html[/b]
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]b.pdf[/b]
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();
[b]c.xls[/b]
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);
[b]4.关闭任务[/b]
task.close();
[b]5.关闭报表[/b]
reportEngine.shutdown();
Platform.shutdown();