JasperReport Output to MS Word(.docx) - Formatting issue

I have a simple Jasper Report created using Jaspersoft Studio 6.3.1 and I have couple of rectangle element with backcolor in it and also couple of line elements.

Now from my Java code, I am trying to generate report in different formats using JasperPrint and trying to generate PDF and MS Word (.docx) version of this report by passing datasource from there. This code runs successfully and generates PDF and docx versions, but those rectangle and line elements with backcolor are only visible in PDF version and not in MS Word version. 

Is that a normal behavior or it is possible to get all that formatting in Word version as well? If yes, then can you please share code snippet to do that? I'm using following code to generate PDF and Word versions.

 

     JasperPrint jasperPrint = JasperFillManager.fillReport(reportName, params, vnDataSource.create(jasperReport));
       
     // exporting process
    // 1- export to PDF
    JasperExportManager.exportReportToPdfFile(jasperPrint, fileName + ".pdf");
    
    // 2- export to Word
    JRDocxExporter exporter = new JRDocxExporter();
    exporter.setExporterInput(new SimpleExporterInput(jasperPrint));      
    File exportReportFile = new File(fileName + ".docx");
    exporter.setExporterOutput(new SimpleOutputStreamExporterOutput(exportReportFile));
    exporter.exportReport();
 
Any help is much appreciated!!
maulik_nanavaty's picture
Joined: Mar 30 2017 - 4:11pm
Last seen: 6 years 6 months ago

Thanks for your answer, but sorry I didn't get that. How did you fix the xls issue? Basically is there any specific code which goes on Java side when we export and print the report in MS Word or fix is really in the .jrxml file at the design time?

maulik_nanavaty - 6 years 6 months ago

2 Answers:

It's a normal behavior with JasperReports for all Office document type exports.

You'll need to customize the exporter to make it work like I did with xls exporter.

http://community.jaspersoft.com/questions/968571/xls-export-missing-over...

hozawa's picture
190845
Joined: Apr 24 2010 - 4:31pm
Last seen: 4 years 3 months ago

Thanks for your answer, but sorry I didn't get that. How did you fix the xls issue? Basically is there any specific code which goes on Java side when we export and print the report in MS Word or fix is really in the .jrxml file at the design time?

maulik_nanavaty's picture
Joined: Mar 30 2017 - 4:11pm
Last seen: 6 years 6 months ago
Feedback