如何用代码导出报表?

[b]1.创建报表引擎[/b]
[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();
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值