Reputation: 1342
I am trying to generate a docx
in jasper report. I have this code:
JRDocxExporter exporter = new JRDocxExporter();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, baos);
exporter.exportReport();
How do I write the report out to file? Most of the examples I have seen are all around using servlets.
Upvotes: 5
Views: 19060
Reputation: 21710
JRExporterParameter is deprecated since jasper version 5.6
The current way since this version would be:
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();
Upvotes: 8
Reputation: 3534
Add the parameter JRExporterParameter.OUTPUT_FILE_NAME
to specify the file and remove the parameter JRExporterParameter.OUTPUT_STREAM
.
JRDocxExporter exporter = new JRDocxExporter();
exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, "myreport.docx");
exporter.exportReport();
Upvotes: 10