首页 > 解决方案 > 在 xlsx 中自动下载 birt 报告

问题描述

我开发了一个 BIRT 报告,它工作正常,但是当我打开一个 HTML 预览屏幕并在那里我可以将它导出为不同的格式时,我希望人们运行或报告时自动下载 Excel 格式(xlsx),我见过几个类型,我得到了 java 代码,但它有一些错误(在打开报告的部分),我也不确定如何在我的报告(.rptdesign)中引用该 java 代码。你能帮我执行这个自动导出过程吗?谢谢!

公共类 EXCELRenderOption 扩展 RenderOption{

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

ReportDesign 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();

标签: javaxlsxbirt

解决方案


推荐阅读