public static void main(String[] args) { try { // 1) Load Docx file by filling Freemarker template engine and cache // it to the registry String reportId = "DumTest"; InputStream in = MavenProjectDumperWithFreemarker.class.getResourceAsStream( "DocxProjectWithFreemarkerList.docx"); IXDocReport report = XDocReportRegistry.getRegistry().loadReport(in, reportId, TemplateEngineKind.Freemarker); // IMPORTANT : cache the original document to use dump. report.setCacheOriginalDocument(true); FieldsMetadata metadata = report.createFieldsMetadata(); metadata.addFieldAsList("developers.name"); metadata.addFieldAsList("developers.lastName"); metadata.addFieldAsList("developers.mail"); // 2) Create context Java model IContext context = report.createContext(); // populateWithMap( context ); populateWithPojo(context); // Eclipse project dump as folder. MavenProjectDumperOptions options = new MavenProjectDumperOptions(); options.setBaseDir(new File("target/maven-dump-ftl")); // EclipseProjectDumper.getInstance().dump( report, context, option, null ); report.dump(context, options, null); } catch (IOException e) { e.printStackTrace(); } catch (XDocReportException e) { e.printStackTrace(); } }
public static void main(String[] args) throws IOException, XDocReportException, SQLException { InputStream in = GenerateDocxReportSimple.class.getResourceAsStream("test1.docx"); IXDocReport report = XDocReportRegistry.getRegistry().loadReport(in, TemplateEngineKind.Velocity); FieldsMetadata metadata = report.createFieldsMetadata(); metadata.load("test", Test.class, false); metadata.load("tests", Test.class, true); metadata.load("formatter", Formatter.class); metadata.load("group", Group.class); Test test = new Test(new Date(), "Test"); List<Test> tests = new ArrayList<Test>(); tests.add(new Test(new Date(), "Test1")); tests.add(new Test(new Date(1000), "Test2")); IContext context = report.createContext(); Formatter formatter = new Formatter(); context.put("formatter", formatter); context.put("group", new Group()); context.put("test", test); context.put("tests", tests); List<Map<String, Object>> testMap = new ArrayList<Map<String, Object>>(); Map<String, Object> map1 = new HashMap<String, Object>(); map1.put("currentDate", new Date()); map1.put("name", "Name1"); map1.put("val", new BigDecimal(10)); Map<String, Object> map2 = new HashMap<String, Object>(); map2.put("currentDate", new Date(11110000)); map2.put("name", "Name1"); map2.put("val", new BigDecimal(20.1)); Map<String, Object> map3 = new HashMap<String, Object>(); map3.put("currentDate", new Date(11110000)); map3.put("name", "Name1"); map3.put("val", new BigDecimal(30.1)); Map<String, Object> map4 = new HashMap<String, Object>(); map4.put("currentDate", new Date(111110000)); map4.put("name", "Name2"); map4.put("val", new BigDecimal(10.5)); Map<String, Object> map5 = new HashMap<String, Object>(); map5.put("currentDate", new Date()); map5.put("name", "Name2"); map5.put("val", new BigDecimal(11.5)); testMap.add(map1); testMap.add(map2); testMap.add(map3); testMap.add(map4); testMap.add(map5); metadata.addFieldAsList("testMap.currentDate"); metadata.addFieldAsList("testMap.name"); metadata.addFieldAsList("testMap.val"); context.put("testMap", testMap); OutputStream out = new FileOutputStream(new File("test1_out.docx")); report.process(context, out); }