word文档转化成ftl文件

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了word文档转化成ftl文件相关的知识,希望对你有一定的参考价值。

word模版,另存成test.xml ,然后修改参数 。将test.xml改为test.ftl.

然后用网上的这段代码生成word文档。  打开时总是提示如下图(数据填入正确)

public void createDoc()

//要填入模本的数据文件

Map<String,String> dataMap=new HashMap<String,String>();

getData(dataMap);

//设置模本装置方法和路径,FreeMarker支持多种模板装载方法。可以重servlet,classpath,数据库装载,

//这里我们的模板是放在com.havenliu.document.template包下面

configuration.setClassForTemplateLoading(this.getClass(), "");

Template t=null;

try

//test.ftl为要装载的模板

t = configuration.getTemplate("test.ftl");

catch (IOException e)

e.printStackTrace();

//输出文档路径及名称

File outFile = new File("D:/outFile.xml");

Writer out = null;

try

out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outFile)));

catch (FileNotFoundException e1)

e1.printStackTrace();

 

        try

t.process(dataMap, out);

catch (TemplateException e)

e.printStackTrace();

catch (IOException e)

e.printStackTrace();

finally

       

        try

out.close();    //释放流

catch (IOException e)

// TODO Auto-generated catch block

e.printStackTrace();

       

参考技术A 另存为xml文件,直接更改后缀名为.ftl 参考技术B 复制-粘贴

以上是关于word文档转化成ftl文件的主要内容,如果未能解决你的问题,请参考以下文章

java freemarker 通过ftl模板导出word文档

话说office 2010 word文档和PPT是可以转化成PDF文档的,为啥我的word转化过来后乱码了?怎么破?谢谢~~

PDF Document转化成word

怎么将网页转换成Word

mac怎么把word格式转化成pdf格式?

将word怎么转化html