Search code examples
javajasper-reportsdoc

How to generate a doc file using Jasper Report


Using jasper-reports 5.6.1 I am able to generate the reports in pdf format, but I am not able figure out how to generate a .doc format by using jasper.

      byte[] exportReportToPdf = JasperExportManager.exportReportToPdf(print);

is for generating a pdf format file like this is there any similar view class for doc format?


Solution

  • Try like this

    JasperPrint jasperPrint = JasperFillManager.fillReport("myReport.jasper", reportParameters, dataSource);
    
    Exporter exporter = new JRDocxExporter();
    exporter.setExporterInput(new SimpleExporterInput(jasperPrint));
    
    File exportReportFile = new File("D:\\Temp\\report.docx");
    
    exporter.setExporterOutput(new SimpleOutputStreamExporterOutput(exportReportFile));
    
    exporter.exportReport();
    

    HTH