コードでレポートをエクスポートする方法
1.レポートエンジンの作成
2.設計プロセッサの作成
3.エクスポート
IRunAndRenderTask task = reportEngine.createRunAndRenderTask(reportRunnable);
a.html
b.pdf
c.xls
4.タスクのクローズ
task.close();
5.レポートのクローズ
reportEngine.shutdown();
Platform.shutdown();
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();