当前位置: 首页>編程日記>正文

Java生成word 并导出简历

Java生成word 并导出简历

先创建一个word文件 内容改成你要生成的格式 再生成.ftl文件
话不多说 上代码!
@Override
public void exportword(HttpServletResponse response, HttpServletRequest request, Long id) throws IOException {
String conf_filename = this.getClass().getClassLoader().getResource("").getPath()
+ System.getProperty(“file.separator”) + “fdfs_client.conf”;
//** 初始化配置文件 //
Configuration configuration = new Configuration();
//
* 设置编码 //
configuration.setDefaultEncoding(“utf-8”);
//
* 我的ftl文件是放在D盘的**//*
String fileDirectory = Tools.getvalue(“project_maindir”);
//String fileDirectory = “D:\”;
//** 加载文件 //
configuration.setDirectoryForTemplateLoading(new File(fileDirectory));
//
* 加载模板 //
Template template = configuration.getTemplate(“AA.ftl”);
//
* 准备数据 //
Map<String,Object> dataMap = new HashMap<String, Object>();
Map<String,Object> map = new HashMap<String, Object>();
//根据会员ID查询出简历基本信息
ResumeInformation resumeVo = resumeInformationMapper.findResumePreviewByMid(id);
if(resumeVo.getPostnature()!=null&&!"".equals(resumeVo.getPostnature())){
String[] ids = resumeVo.getPostnature().split(",");
//根据IDS查询出参数名称并列显示
String postnature = paramDictionaryMapper.findParamById(ids);
resumeVo.setPostnatureString(postnature);
}
if(resumeVo.getUpdateTime()!=null){
resumeVo.setUpdateHours(DateUtils.DateToString(resumeVo.getUpdateTime(), DateStyle.YYYY_MM_DD));
}
//根据会员ID查询出工作经验`
List workExperienceList = workExperienceMapper.findWorkExperienceListByMid(id);
//根据会员ID查询出项目经验
List projectExperienceList = projectExperienceMapper.findProjectExperienceListByMid(id);
//根据会员ID查询出教育经历
List educationExperienceList = educationExperienceMapper.findEducationExperienceListByMid(id);
//根据会员ID查询出培训经历
List trainExperienceList = trainExperienceMapper.findTrainExperienceListByMid(id);
//根据会员ID查询出作品网站
List worksWebsiteList = worksWebsiteMapper.findWorksWebsiteListByMid(id);
map.put(“resumeVo”, resumeVo);
if(resumeVo.getPhotoUrl()!=null){
String fileData = resumeVo.getPhotoUrl();
fileData = fileData.substring(7, fileData.length());
String firstName=fileData.substring(fileData.lastIndexOf(’/’)+1);
int indexOf = fileData.indexOf("/");
String url2 = fileData.substring(indexOf+1);
int indexOf2 = url2.indexOf("/");
String group = url2.substring(0, indexOf2);
String path = url2.substring(indexOf2+1);
//循环下载路径
String urlshared = App.downloadFiles(group, path, conf_filename, request,firstName);
InputStream in = null;
byte[] data = null;
try {
in = new FileInputStream(urlshared);
data = new byte[in.available()];
in.read(data);
in.close();
} catch (Exception e) {
e.printStackTrace();
}finally {
if(in != null){
in.close();
}
}
//
* 进行base64位编码 //
BASE64Encoder encoder = new BASE64Encoder();
dataMap.put(“img”,encoder.encode(data));
}else{
//
* 图片路径 //
String imagePath = request.getSession().getServletContext().getRealPath("/resources/images/defaultHeadimg.png");//获取图像在项目中的路径
//
* 将图片转化为**//*
InputStream in = null;
byte[] data = null;
try {
in = new FileInputStream(imagePath);
data = new byte[in.available()];
in.read(data);
in.close();
} catch (Exception e) {
e.printStackTrace();
}finally {
if(in != null){
in.close();
}
}
//** 进行base64位编码 //
BASE64Encoder encoder = new BASE64Encoder();
dataMap.put(“img”,encoder.encode(data));
}
//名称
dataMap.put(“name”,resumeVo.getRealName());
//性别
dataMap.put(“sex”,resumeVo.getSexs());
//年龄
dataMap.put(“age”,resumeVo.getAge());
//工作年限
if(resumeVo.getWorkExe()!=null){
if(resumeVo.getWorkExe()==0){
dataMap.put(“workExe”,“一年以下工作经验”);
}else{
dataMap.put(“workExe”,resumeVo.getWorkExe()+“年工作经验”);
}
}else{
dataMap.put(“workExe”,“无工作经验”);
}
//现居住市级
dataMap.put(“nowCity”,resumeVo.getNowCity());
//隐藏中间四位手机号
String s = resumeVo.getPhone();
String replaceAll = s.replaceAll("(\d{3})\d{4}(\d{4})", "$1
***$2");
//手机号
dataMap.put(“phone”, replaceAll);
//邮箱
if(resumeVo.getEmail()!=null && resumeVo.getEmail().length()>0){
StringBuilder email = new StringBuilder();
int num;
String str = “”;
email.append(resumeVo.getEmail());
num = email.indexOf("@");
for (int i = 0; i < num; i++) {
str = str + “*”;
}
email = email.replace(3,num,str);
System.out.println(email);
dataMap.put(“email”, email);
}else{
dataMap.put(“email”, “”);
}
//工作性质
dataMap.put(“postnature”,resumeVo.getPostnatureString());
//期望工作地点
dataMap.put(“workCity”,resumeVo.getWorkCity());
//期望职业
dataMap.put(“posiName”, resumeVo.getPosiName());
//期望行业
dataMap.put(“industryName”,resumeVo.getIndustryName());
//期望月薪
dataMap.put(“offers”,resumeVo.getOffers());
//自我评价
dataMap.put(“explored”,resumeVo.getExplored());
//分割个人标签
if(resumeVo.getPersonTag()!=null){
String personTag = resumeVo.getPersonTag().replaceAll(","," “);
dataMap.put(“personTag”,personTag);
}else{
dataMap.put(“personTag”,”");
}
//工作经验
dataMap.put(“workExperienceList”, workExperienceList);
//根据会员ID查询出项目经验
dataMap.put(“projectExperienceList”, projectExperienceList);
//根据会员ID查询出教育经历
dataMap.put(“educationExperienceList”, educationExperienceList);
//根据会员ID查询出培训经历
dataMap.put(“trainExperienceList”, trainExperienceList);
//根据会员ID查询出作品网站
dataMap.put(“worksWebsiteList”, worksWebsiteList);
//Map<String,Map<String,Object>> dataMaps = new LinkedHashMap<String,Map<String,Object>>();
//List list=studymetarialdetailService.findstudymetarials(sId,docId);
//循环遍历list
/*for (Studymetarialdetail studymetarialdetail : list) {
String fileData = studymetarialdetail.getFirstPath();
String description = studymetarialdetail.getDescrip()==null?"":studymetarialdetail.getDescrip();

		String firstName=fileData.substring(fileData.lastIndexOf('/')+1);int indexOf = fileData.indexOf("/");String url2 = fileData.substring(indexOf+1);int indexOf2 = url2.indexOf("/");String group = url2.substring(0, indexOf2);String path = url2.substring(indexOf2+1);//循环下载路径String urlshared = App.downloadFiles(group, path, conf_filename, request,firstName);InputStream in = null;byte[] data = null;try {in = new FileInputStream(urlshared);data = new byte[in.available()];in.read(data);in.close();} catch (Exception e) {e.printStackTrace();}finally {if(in != null){in.close();}}//** 进行base64位编码 **//*BASE64Encoder encoder = new BASE64Encoder();//** 在ftl文件中有${textDeal}这个标签**//*//dataMap.put("textDeal","一下省略一万字");//** 图片数据**//*dataMap.put("描述"+i+":"+description,encoder.encode(data));i++;}dataMaps.put("dataMaps", dataMap);*///dataMap.put("images", images);//dataMap.put("titles", titles);//** 指定输出word文件的路径 **//*long currentTime = System.currentTimeMillis();//SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH-mm-ss");//Date date = new Date(currentTime);String filename = "JM"+currentTime+".doc";String outFilePath = Tools.getPropertie("upload.down")+filename;//  String downpath = Tools.getvalue("upload.down");File docFile = new File(outFilePath);FileOutputStream fos = new FileOutputStream(docFile);Writer out = new BufferedWriter(new OutputStreamWriter(fos, "utf-8"),10240);try {template.process(dataMap, out);;} catch (TemplateException e) {e.printStackTrace();}if(out != null){out.close();}Tools.fileDown(response, outFilePath, filename);}

最后一步是文件下载 贴上代码
/**
* 文件流下载
* @throws IOException
*/
public static void fileDown(HttpServletResponse resp,String filepath,String filename) throws IOException{
resp.setContentType(“application/force-download”);
InputStream in = new FileInputStream(filepath);
resp.setHeader(“Content-Disposition”, “attachment;filename=”" + filename + “”");
resp.setContentLength(in.available());
OutputStream out = resp.getOutputStream();
byte[] b = new byte[1024];
int len = 0;
while((len = in.read(b))!=-1){
out.write(b, 0, len);
}
out.flush();
out.close();
in.close();
}


https://www.fengoutiyan.com/post/15080.html

相关文章:

  • 导出简历乱码
  • 简历java
  • wps简历模板在哪里找
  • 创建word文档的三种方法
  • testlink导出word
  • word简历怎么生成图片
  • word如何复制整页简历
  • 前程无忧简历导出word
  • 鏡像模式如何設置在哪,圖片鏡像操作
  • 什么軟件可以把圖片鏡像翻轉,C#圖片處理 解決左右鏡像相反(旋轉圖片)
  • 手機照片鏡像翻轉,C#圖像鏡像
  • 視頻鏡像翻轉軟件,python圖片鏡像翻轉_python中鏡像實現方法
  • 什么軟件可以把圖片鏡像翻轉,利用PS實現圖片的鏡像處理
  • 照片鏡像翻轉app,java實現圖片鏡像翻轉
  • 什么軟件可以把圖片鏡像翻轉,python圖片鏡像翻轉_python圖像處理之鏡像實現方法
  • matlab下載,matlab如何鏡像處理圖片,matlab實現圖像鏡像
  • 圖片鏡像翻轉,MATLAB:鏡像圖片
  • 鏡像翻轉圖片的軟件,圖像處理:實現圖片鏡像(基于python)
  • canvas可畫,JavaScript - canvas - 鏡像圖片
  • 圖片鏡像翻轉,UGUI優化:使用鏡像圖片
  • Codeforces,CodeForces 1253C
  • MySQL下載安裝,Mysql ERROR: 1253 解決方法
  • 勝利大逃亡英雄逃亡方案,HDU - 1253 勝利大逃亡 BFS
  • 大一c語言期末考試試題及答案匯總,電大計算機C語言1253,1253《C語言程序設計》電大期末精彩試題及其問題詳解
  • lu求解線性方程組,P1253 [yLOI2018] 扶蘇的問題 (線段樹)
  • c語言程序設計基礎題庫,1253號C語言程序設計試題,2016年1月試卷號1253C語言程序設計A.pdf
  • 信奧賽一本通官網,【信奧賽一本通】1253:抓住那頭牛(詳細代碼)
  • c語言程序設計1253,1253c語言程序設計a(2010年1月)
  • 勝利大逃亡英雄逃亡方案,BFS——1253 勝利大逃亡
  • 直流電壓測量模塊,IM1253B交直流電能計量模塊(艾銳達光電)
  • c語言程序設計第三版課后答案,【渝粵題庫】國家開放大學2021春1253C語言程序設計答案
  • 18轉換為二進制,1253. 將數字轉換為16進制
  • light-emitting diode,LightOJ-1253 Misere Nim
  • masterroyale魔改版,1253 Dungeon Master
  • codeformer官網中文版,codeforces.1253 B
  • c語言程序設計考研真題及答案,2020C語言程序設計1253,1253計算機科學與技術專業C語言程序設計A科目2020年09月國家開 放大學(中央廣播電視大學)
  • c語言程序設計基礎題庫,1253本科2016c語言程序設計試題,1253電大《C語言程序設計A》試題和答案200901
  • 肇事逃逸車輛無法聯系到車主怎么辦,1253尋找肇事司機