public static void main(String[] args) { ITemplateEngine templateEngine = new FreemarkerTemplateEngine(); IXDocReport report = new ODTReport(); report.setDebugger(SysOutDebugger.INSTANCE); report.setTemplateEngine(templateEngine); FieldsMetadata metadata = new FieldsMetadata(); metadata.addFieldAsList("lines.reference"); report.setFieldsMetadata(metadata); try { // File f = new File();; report.load(TestODTWithFreemarker.class.getResourceAsStream("TestODTWithFreemarker.odt")); IContext context = report.createContext(); Project project = new Project("XDocReport"); context.put("project", project); List<Command> commands = new ArrayList<Command>(); commands.add(new Command("ref1")); commands.add(new Command("ref2")); context.put("lines", commands); context.put("adresse_magasin", "yessssssssssss"); File file = new File("out/TestODTWithFreemarker_Out.docx"); report.process(context, new FileOutputStream(file)); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (XDocReportException e) { e.printStackTrace(); } }
/** * Génération d'un document de démonstration, contenant uniquement une variable simple de type * texte. */ public static void demoSimple() { String titre = "Document de démonstration COUCOU"; IXDocReport report = XDocReportRegistry.getRegistry().getReport("demoSimple.odt"); report.setTemplateEngine(new FreemarkerTemplateEngine()); try { IContext context = report.createContext(); context.put("titre", titre); ByteArrayOutputStream out = new ByteArrayOutputStream(); report.process(context, out); InputStream is = new ByteArrayInputStream(out.toByteArray()); renderBinary(is, "demoSimple.odt"); } catch (XDocReportException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } // renderDocument(titre); }