freemarker开发word步骤

来源:互联网 发布:编程学校多少钱 编辑:程序博客网 时间:2024/06/06 08:35

1、从网上找到ftl模版。

2、新建word文件,写上需要的格式。

3、根据上述两个文件合并成需要的ftl文件,注意格式和开头结尾部分。

4、下载jar包,导入工程中。

5、利用下面的

  configuration.setClassForTemplateLoading(this.getClass(), "../../com/template");
  Template t = null;
  try{
   //test.ftl为要装载的模板
   t = configuration.getTemplate("test.ftl");
  }catch(IOException e){
   e.printStackTrace();
  }
  //输出文档路径及名称
  File outFile = new File("d:/testtt.doc");
  Writer out = null;
  try{
   FileOutputStream fos = new FileOutputStream(outFile);
   OutputStreamWriter oWriter = new OutputStreamWriter(fos,"UTF-8");
   out = new BufferedWriter(oWriter);
  }catch(FileNotFoundException e1){
   e1.printStackTrace();
  }
  try{
   t.process(dataMap, out);
  }catch(TemplateException e){
   e.printStackTrace();
  }catch(IOException e1){
   e1.printStackTrace();
  }

 

利用dataMap.put("userName","Jimmy");方式赋值。

原创粉丝点击