presently the jasper reporting tool we are using is exported to pdf...Now we want it to be exported to Ms word file.
1 Answer:
Posted on July 4, 2018 at 1:48pm
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
I am doing this in java struts..so is there a need for jar files