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();
}
Java生成word 并导出简历相关推荐
- java 生成word表格
JAVA生成WORD文件的方法目前有以下种: 一种是jacob 但是局限于windows平台 往往许多JAVA程序运行于其他操作系统 在此不讨论该方案.(需要下载jacob.jar以及jacob.dl ...
- java生成word和pdf的几种方法的优缺点对比
JAVA生成word优缺点对比 所用技术 优点 缺点 Jacob 功能强大 代码量大,设置样式繁琐:需要windows平台支持,无法跨平台 Apache POI 读写excel功能强大.操作简单 一般 ...
- 记录一次用Java生成word文档的经验
业务背景 最近接到一个需求需要将学员的基本信息生成word格式的内容,word的格式如下图所示 开发的任务就是将学员的信息替换掉表格中的** 即可,感觉还蛮简单的. 相信大家以前做的最多的是Java和 ...
- Java生成word通报(使用echart、poi-tl、PhantomJS)
Java生成word通报(使用echart.poi-tl.PhantomJS) 前段时间客户需要系统自动生成服务通报,word文档中要有图片.表格.文字.第一次做这种通报,项目经理又想用以前的方式,只 ...
- java生成word,html文件并将内容保存至数据库 (http://blog.163.com/whs3727@126/blog/static/729915772007325112014115/)
java生成word,html文件并将内容保存至数据库 2007-04-25 11:20:14| 分类: Java|举报|字号 订阅 http://hi.baidu.com/litertiger/b ...
- [摘]用Java生成Word文档
开发中隔三叉五的就要用到Word,经常被搞得不胜其烦,不过这次找到了不少好例子,干脆将他们都摘了过来,内容如下: 1. poi是apache的一个项目,不过就算用poi你可能都觉得很烦,不过不要紧,这 ...
- 用java生成word文档(转载)
用java生成word文档 poi是apache的一个项目,不过就算用poi你可能都觉得很烦,不过不要紧,这里提供了更加简单的一个接口给你: 下载经过封装后的poi包: 这个包就是:tm-extrac ...
- java生成word几种解决方案
1. Jacob是Java-COM Bridge的缩写,它在Java与微软的COM组件之间构建一座桥梁.使用Jacob自带的DLL动态链接库,并通过JNI的方式实现了在Java平台上对COM程序的调用 ...
- java根据word模板导出_java如何根据word模板生成word文档
展开全部 先下载jacob_1.10.1.zip. 解压后将jacob.dll放到windows/system32下面或\j2sdk\bin下面. 将jacob.jar加入项目. /* * Java2 ...
- Java生成Word文档
在开发文档系统或办公系统的过程中,有时候我们需要导出word文档.在网上发现了一个用PageOffice生成word文件的功能,就将这块拿出来和大家分享. 生成word文件与我们编辑word文档本质上 ...
最新文章
- Java游戏服务器系列之Netty详解
- Boost--Graph
- 备忘: VC++ 自动适用编译两种模式库文件 (DLL, LIB)
- RxJava 2.x 入门
- poj 1164 The Castle
- union 和 union all
- 模拟网页行为之实践四
- 中油即时通信电脑版_市场营销之即时通讯营销
- 如何打造高大上的微信朋友圈 打造微信高逼格朋友圈教程
- 【论文写作】课程指导平台的开发中需求分析如何写
- JQueryDOM之属性操作
- 项目管理(七)- 项目利益相关者责任
- plSQL中修改代码字体的大小
- JVM-深入理解JVM内存模型、类加载机制、内存分配机制
- Java中的接口详解
- C语言 | 复制字符串 不用strcpy
- Microbime:微生物组学领域的标准制定
- 冈萨雷斯图像处理---非锐化掩蔽和高提升滤波
- the password has expired解决方法
- 通达信最新交易接口系统开发源码有哪些?
热门文章
- 彩灯控制器课程设计vhdl_基于VHDL的彩灯控制器设计与实现.doc
- 【已解决】java.lang.IllegalStateException: Only fullscreen opaque activities can request orientation
- 基于单片机的红外检测及语音响应系统
- android 坐标度分秒转换工具,经纬度格式转换定位工具
- linux 监听 ipv6,zabbix 监控 ipv6
- 动态数据中心:微软私有云解决方案
- 【laravel】切换语言包 中文,英文
- 日系PC厂商为问题希捷硬盘提供固件更新
- 政务型CMS内容管理系统
- 爱普生EPSON打印机 ME1+ (ME1)清零软件及方法