JAVA FreeMarker导出word
2015-05-26 23:08
225 查看
编辑word模板(Template)文件
1.word中新建一文档,设计好要导出的模板样式。其中添加参数:${export}
如:
2、将处理好的的word模板,另存为xml格式或.ftl格式的文档。
FreeMaker使用Template文件导出word
1.设置参数configuration = new Configuration(); configuration.setDefaultEncoding("utf-8");
2.装载数据
数据可来自请求、classpath、数据库等。
Map daaMapt=new HashMap(); daaMapt.put...
3.加载模板
//这里我们的模板是放在com.cist.bayonet.mainstat.service.impl包下面 configuration.setClassForTemplateLoading(this.getClass(), "/com/cist/bayonet/mainstat/service/impl");
Template t=null; try { //sgxxb_info.ftl为要装载的模板 t = configuration.getTemplate("sgxxb_info.ftl"); catch (IOException e) { e.printStackTrace(); }
4、导出模板数据到word
File outFile = new File(path+"/name.doc"); Writer out = null; try { FileOutputStream fos = new FileOutputStream(outFile); OutputStreamWriter oWriter = new OutputStreamWriter(fos,"UTF-8");//这个地方对流的编码不可或缺, //使用main()单独调用时,应该可以,但是如果是web请求导出时导出后word文档就会打不开,并且包XML文件错误。主要是编码格式不正确,无法解//析。 out = new BufferedWriter(oWriter); } catch (FileNotFoundException e1) { e1.printStackTrace();
} try { t.process(dataMap, out); } catch (TemplateException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); }
相关文章推荐
- java中使用freemarker导出word文档
- java基于freemarker导出指定word格式带多图片源码。
- java导出2007版word(docx格式)freemarker + xml 实现
- Java用freemarker导出word
- java freemarker导出word时添加或勾选复选框
- 【Java】导出word文档之freemarker导出
- Java用freemarker导出word
- Java使用freemarker导出word文档
- java用freemarker导出数据到word(含多图片)
- Java 使用Freemarker导出word 文档,解决当一段内容中既有文字又有图片的问题
- Java用freemarker导出word
- Java使用freemarker导出word和excel
- Java用Freemarker导出word 内容换行
- java freemarker 实现word文件导出
- java freemarker 通过ftl模板文件导出word文件发现在有中文地方出现在乱码,打开word文件提示xml错误解决办法
- Java用freemarker导出word
- Java用freemarker导出word
- 超详细 Java使用freemarker模板技术导出word
- Java用freemarker导出word
- java导出word之freemarker导出