用 freemarker 生成 word 文档

用 freemarker 生成 word 文档

ID:12676031

大小:52.00 KB

页数:6页

时间:2018-07-18

用 freemarker 生成 word 文档_第1页
用 freemarker 生成 word 文档_第2页
用 freemarker 生成 word 文档_第3页
用 freemarker 生成 word 文档_第4页
用 freemarker 生成 word 文档_第5页
资源描述:

《用 freemarker 生成 word 文档》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库

1、用Freemarker生成word文档1.       用word写一个需要导出的word模板,然后存为xml格式。2.       将xml中需要动态修改内容的地方,换成freemarker的标识符,例如: ${year}

2、:r>年度工作报告3.       用代码生成: importfreemarker.template.Configuration;importfreemarker.template.Template;importjava.io.*;importjava.util.HashMap;importjava.util.Map;/***@Classname:CreateDoc*

*Shortdescriptiononthepurposeofthe

3、program.*@author:youfeng*@modified:8/29/11*/publicclassCreateDoc{privateConfigurationconfiguration=null;publicCreateDoc(){configuration=newConfiguration();configuration.setDefaultEncoding("utf-8");}publicvoidcreate()throwsException{Mapmap=newHashMap()

4、;map.put("date","2011");map.put("modifyDate","2011/8/29");map.put("modifyUser","ZhuYouFeng");configuration.setClassForTemplateLoading(this.getClass(),"/docTemplate/");Templatet=configuration.getTemplate("doc1.ftl");FileoutFile=newFile("D:/outFile.doc");Writerout=newBufferedWriter(

5、newOutputStreamWriter(newFileOutputStream(outFile)));t.process(map,out);}publicstaticvoidmain(String[]args)throwsException{newCreateDoc().create();}} 添加图片如果你需要在word中添加图片,那你就在第一步制作模板时,加入一张图片占位,然后打开xml文档,可以看到如下的一片base64编码后的代码:1 iVBORw0…(很省略很省略)…CC只要将base64的代码替换成例如:${image},如下:1 ${image}这里要注意“>${image}<”这尖括号中间不能加任何其他的诸如空格,tab,换行等符号。然后用代码生成: importfreemarker.template.Configuration;importfreemarker.template.Templa

7、te;importsun.misc.BASE64Encoder;importjava.io.*;importjava.util.HashMap;importjava.util.Map;/***@Classname:CreateDoc*@author:youfeng*@modified:8/29/11*/publicclassCreateDocWithImage{privateConfigurationconfiguration=null;publicCreateDocWithImage(){configuration=newConfiguration();

8、configuration.setDefaultEncoding(

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。