Commit 302789f6 by gaopeng

word生成加方法

parent 20cbb88d
...@@ -127,6 +127,47 @@ public class WordDataExportor { ...@@ -127,6 +127,47 @@ public class WordDataExportor {
} }
/** /**
* 生成word
* @param dataMap
* @param templateName
* @return
* @author linweibin
* @date 2017年5月22日 下午5:22:38
*/
@SuppressWarnings("deprecation")
public static void generateWord(Class clazz, Map<String, Object> dataMap, String templateName, File tmpdir, String fileName) {
logger.info("开始生成word+++");
try {
// 创建配置实例
Configuration configuration = new Configuration();
// 设置编码
configuration.setDefaultEncoding("UTF-8");
// 获取template文件路径
configuration.setClassForTemplateLoading(clazz, "/template");
// 获取模板
Template template = configuration.getTemplate(templateName);
// 输出文件
File outFile = new File(tmpdir, fileName);
// 将模板和数据模型合并生成文件
Writer out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outFile), "UTF-8"));
// 生成文件
template.process(dataMap, out);
logger.info("生成word+++成功");
// 关闭流
out.flush();
out.close();
} catch (Exception e) {
logger.error("生成word异常+++" + e.getMessage(), e);
}
}
/**
* 生成随机文件名 * 生成随机文件名
* @return * @return
* @author linweibin * @author linweibin
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment