package com; import java.io.BufferedWriter; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStreamWriter; import java.io.Writer; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import freemarker.template.Configuration; import freemarker.template.Template; import freemarker.template.TemplateException; public class Word { private Configuration configuration = null; public Word() { configuration = new Configuration(); configuration.setDefaultEncoding("utf-8"); } public void createDoc() { // 要填入模本的数据文件 Map dataMap = new HashMap(); getData(dataMap); // 设置模本装置方法和路径,FreeMarker支持多种模板装载方法。可以重servlet,classpath,数据库装载, // ftl文件存放路径 configuration.setClassForTemplateLoading(this.getClass(), "/com/ftl"); Template t = null; try { // test.ftl为要装载的模板 t = configuration.getTemplate("QQ.ftl"); t.setEncoding("utf-8"); } catch (IOException e) { e.printStackTrace(); } // 输出文档路径及名称 File outFile = new File("F:/2013/test.doc"); Writer out = null; try { out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outFile), "utf-8")); } catch (Exception e1) { e1.printStackTrace(); } try { t.process(dataMap, out); out.close(); } catch (TemplateException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } /** * * 注意dataMap里存放的数据Key值要与模板中的参数相对应 * @param dataMap */ private void getData(Map dataMap) { dataMap.put("title", "Test"); dataMap.put("nian", "二零一二"); dataMap.put("danweiming", "陕西"); List lists = new ArrayList(); WordBean w1 = new WordBean(); w1.setPaixu("1"); w1.setBiaoduan("标段一"); WordBean w2 = new WordBean(); w2.setPaixu("2"); w2.setBiaoduan("标段二"); lists.add(w1); lists.add(w2); dataMap.put("wordBeans", lists); dataMap.put("paiming", "1"); dataMap.put("biaoduan", "标段一"); } public static void main(String[] args) { new Word().createDoc(); } }

467277 LV13
2024年3月26日
805421159 LV1
2022年2月12日
745075779 LV5
2021年11月12日
chenrj1009 LV1
2021年10月19日
he752650052 LV1
2021年10月13日
1090093031 LV1
2021年10月12日
collerwang867 LV1
2021年9月10日
y6622576 LV9
2021年9月2日
x2b2d2 LV12
2021年8月17日
nidiewojiushiwo LV1
2021年7月22日

qiheideguang LV18
4月10日
3334004690 LV10
2024年5月28日
sccs1984 LV15
2024年5月4日
467277 LV13
2024年3月26日
floweyws LV6
2024年2月5日
cbddbc LV1
2024年1月4日
irivn007 LV15
2023年1月28日
anhao5188
2022年12月19日
暂无贡献等级
1358849392 LV21
2022年11月11日
最代码-彭小康
2022年7月6日
暂无贡献等级