Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to generate, export to word docx file?

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.

like image 225
eeijlar Avatar asked Apr 09 '14 16:04

eeijlar


People also ask

How do I make a DOCX file in Word?

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.

What does Export to DOCX mean?

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'.

How do I automatically extract data from Excel to Word?

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.


1 Answers

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();
like image 60
user432 Avatar answered Oct 27 '22 11:10

user432