5

我正在尝试生成一个docxin jasper 报告。我有这个代码:

JRDocxExporter exporter = new JRDocxExporter();
ByteArrayOutputStream baos = new ByteArrayOutputStream();    
exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, baos);
exporter.exportReport(); 

我如何将报告写入文件?我看到的大多数示例都是围绕使用 servlet 的。

4

2 回答 2

10

添加参数JRExporterParameter.OUTPUT_FILE_NAME以指定文件并删除参数JRExporterParameter.OUTPUT_STREAM

JRDocxExporter exporter = new JRDocxExporter();
exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, "myreport.docx");
exporter.exportReport();
于 2014-04-10T06:42:03.050 回答
8

JRExporterParameter自 jasper 版本 5.6 起已弃用

自此版本以来的当前方式是:

JRDocxExporter export = new JRDocxExporter();
export.setExporterInput(new SimpleExporterInput(jasperPrint));
export.setExporterOutput(new SimpleOutputStreamExporterOutput(new File("path/toMy/report.docx")));

SimpleDocxReportConfiguration config = new SimpleDocxReportConfiguration();
//config.setFlexibleRowHeight(true); //Set desired configuration

export.setConfiguration(config);            
export.exportReport();
于 2015-11-24T10:01:21.637 回答