freemarker+xml生成word文档
public static void main1(String[] args) throws IOException, TemplateException {
Configuration cfg = new Configuration();
cfg.setDirectoryForTemplateLoading(new File("D:\\"));
Template template = null;
template = cfg.getTemplate("template.xml");
template.setEncoding("utf-8");
Map dataMap = new HashMap();
dataMap.put("name", "NAME");
File outFile = new File("D:\\file.doc");
Writer out = null;
out = new BufferedWriter(new OutputStreamWriter(
new FileOutputStream(outFile), "utf-8"));
template.process(dataMap, out);
out.close();
}
D:\\template.xml是模板,模板中动态数据用freemarker标签替换
D:\\file.doc是生成出的word文档