How to export jasper report into msword file?

presently the jasper reporting tool we are using is exported to pdf...Now we want it to be exported to Ms word file. 

riyathadathil's picture
Joined: Jul 4 2018 - 4:46am
Last seen: 4 years 1 month ago

I am doing this in java struts..so is there a need for jar files

riyathadathil - 4 years 1 month ago

1 Answer:

 

 Hi, usin java with Json DataSource:

public class Test {
 
  public static void main(String[] args) {
    try {
      String pathToReports = "/home/test/";
      Map<String, Object> params = new HashMap<>();
      JRDataSource jsonDataSource = new JsonDataSource(new File("/home/test/example.json"));
      JasperReport jasperReport = JasperCompileManager.compileReport(pathToReports + "main.jrxml");
 
      JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, params, jsonDataSource);
 
      //Export to PDF     
      // JasperExportManager.exportReportToPdfFile(jasperPrint, "/home/test/fileName.pdf");
 
      //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();
 
    } catch (Exception e) {}
  }
}

Regards

ecanaveras's picture
Joined: Sep 26 2012 - 11:02am
Last seen: 3 months 3 weeks ago
Feedback