人员简历模板导出
parent
76f1501a28
commit
bc47f697d0
@ -0,0 +1,84 @@
|
||||
package com.engine.organization.util;
|
||||
import freemarker.template.Configuration;
|
||||
import freemarker.template.Template;
|
||||
import freemarker.template.TemplateException;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author
|
||||
* @date
|
||||
* @apiNote 生成动态文档帮助类
|
||||
*/
|
||||
@Data
|
||||
public class WordUtil {
|
||||
private Configuration configuration = null;
|
||||
|
||||
/*
|
||||
* 模板文件存放的目录
|
||||
*/
|
||||
private String baseDir;
|
||||
|
||||
/*
|
||||
* 模板文件名称
|
||||
*/
|
||||
private String templateFile;
|
||||
|
||||
/*
|
||||
* word生成的输出目录
|
||||
*/
|
||||
private String outputDir;
|
||||
|
||||
public WordUtil(){
|
||||
configuration = new Configuration();
|
||||
configuration.setDefaultEncoding("utf-8");
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* <p>转换成word<br>
|
||||
*/
|
||||
public String createWord(Map<String,Object> dataMap){
|
||||
|
||||
configuration.setClassForTemplateLoading(this.getClass(), "");//模板文件所在路径
|
||||
|
||||
Template t = null;
|
||||
|
||||
try {
|
||||
//得到模板文件
|
||||
configuration.setDirectoryForTemplateLoading(new File(baseDir));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
try {
|
||||
t = configuration.getTemplate(templateFile,"utf-8");
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
// GwUtil.getFileNo(""); 调用生成随机数的方法
|
||||
File outFile = new File(outputDir + "222.doc"); //导出文件
|
||||
|
||||
Writer out = null;
|
||||
try {
|
||||
try {
|
||||
out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outFile),"utf-8"));
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} catch (FileNotFoundException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
try {
|
||||
t.process(dataMap, out); //将填充数据填入模板文件并输出到目标文件
|
||||
return outFile.getPath();
|
||||
} catch (TemplateException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return "文档生成失败";
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue