Java html转word,用freemark生成复杂word格式
来源:互联网 发布:python 画图 技巧 编辑:程序博客网 时间:2024/06/05 15:08
1.**制作模板**,要求word版本2003以上。在word写好预定的格式,在需要显示内容的地方写一个占位符。将word save as 成“Single File Web Page(*.mht, *mhtml)”
nodepad++ 打开mht文件,将占位符加上${name},并将文件中的charset设置为utf-8,有时候需要将格式转换utf-8不然中文会出现乱码.
demo: http://download.csdn.net/detail/rehuojunguan/9857489
2.freemark class 主要读取模板 template,根据map的中数据替换mht文件中的 ${key},最后生成word。
public class FreeMarkerDoc {private String templateName = null;private String templatePath = null;private Configuration configuration = null; public FreeMarkerDoc() { configuration = new Configuration(Configuration.VERSION_2_3_21); configuration.setDefaultEncoding("utf-8");}public void generateDoc(Map<String,Object> dataMap, String fileName) throws IOException, TemplateException { Template tempalte = null; configuration.setClassForTemplateLoading(this.getClass(), "/com/freemark/template"); //setServletContextForTemplateLoading(context, "/mht") /WebRoot/ftl目录。 //configuration.setDirectoryForTemplateLoading(new File("C:\\Users\\Desktop\\test")); ///tempalte.setEncoding("utf-8"); tempalte = configuration.getTemplate("test.mht"); File outFile = new File(fileName); Writer out = null; FileOutputStream fos = null; OutputStreamWriter oWriter = null; try { fos = new FileOutputStream(outFile); oWriter = new OutputStreamWriter(fos, "UTF-8"); out = new BufferedWriter(oWriter); tempalte.process(dataMap, out); } finally { if(null != out){ out.close(); } if(null != oWriter){ oWriter.close(); } if(null != fos){ fos.close(); } } }}
阅读全文
0 0
- Java html转word,用freemark生成复杂word格式
- Java使用freemark生成word
- 使用freeMark生成word
- Java动态生成复杂word
- Java 动态生成复杂 Word
- Java 动态生成复杂 Word
- HTML格式字符串生成Word
- C#生成复杂格式的WORD
- java freemark导出word 实现word分页
- Freemark实现Java导出Word
- 完美解决方案:Java生成复杂Word文档
- 完美解决方案:Java生成复杂Word文档
- Java生成复杂word/pdf解决方案
- 完美解决方案:Java生成复杂Word文档
- java word转HTML
- Java Word转Html
- Java Word转Html
- java word转html
- 内置函数
- bzoj4838 树重心分解引发的计数问题!4月份月赛
- 关于开源的一些思考
- Fatal Error[Pe1696]: cannot open source file "intrinsics.h" 的问题
- 原型设计的重要性你真的知道吗?
- Java html转word,用freemark生成复杂word格式
- leetcode 522. Longest Uncommon Subsequence II
- 合并两个排序的链表
- JS(十三)文本框脚本
- #Java 高并发秒杀API 笔记
- XSS攻击常用脚本
- 百练OJ 情报破译-Cryptanalysis(字符串加密解密+串逆序+单词处理)
- tensorflow中tfrecords文件的save和read
- Nginx的模块化体系介绍