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.
Once you have chosen an appropriate location, enter a file name in the 'File name' field. From the 'Save as type' dropdown, ensure 'Word Document (*. docx)' is selected. Click 'Save' to confirm and save the file.
Put simply, . Doc is the older version of a Microsoft Word Document. DocX is the newer version, form versions of Microsoft Word 2007 onwards. Now before you jump in thinking that the added X makes the document extreme or better in some way, that X on the end just stands for 'Office Open XML'.
Click the "Insert" tab > Locate the "Tables" group. Select the "Table" icon > Choose the "Insert Table..." option. Set the "Number of columns," "Number of rows," and "AutoFit behavior" to your desired specifications > Click [OK]. Open the Excel file and use your mouse to select the data you wish to import.
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();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With