sprng 导出指定模板的

SpringBoot 集成webSocket

所需jar包

jxl.jar

java代码

首先选择模板相对目录
InputStream fis = new FileInputStream("/opt/upload/excel/1.xls");
获取excel
Workbook wb = Workbook.getWorkbook(fis);
生成完成后的路径及名字
WritableWorkbook newWb = Workbook.createWorkbook(
new File("/opt/upload/excel/"+userEntity.getNickName()+"简历.xls"), wb);
创建一个sheet页
WritableSheet sheet = newWb.getSheet(0);

根据实际需求在每个label添加相应的描述及数据
if(userResume != null){
     //自然情况
     //姓名
     sheet.addCell(new Label(2, 4, userResume.getName()));
     String sex="";
     if(userResume.getSex() != null){
	if(userResume.getSex() ==1){
		sex = "女";
	}else{
		sex = "男";
	}
		}
       //性别
         sheet.addCell(new Label(5, 4, sex));
         //出生年月
         sheet.addCell(new Label(2, 5, userResume.getBirthday()));
         //民族
         sheet.addCell(new Label(5, 5, userResume.getNation()));
         //婚姻状况
         sheet.addCell(new Label(2, 6, userResume.getMaritalStatus()));
         //居住地
         sheet.addCell(new Label(5, 6, userResume.getProvince()+userResume.getCity()));
         //家庭住址
         sheet.addCell(new Label(2, 7, userResume.getAddress()));
         //最后学历
         sheet.addCell(new Label(2, 8, userResume.getEducation()));
         //职称
         if(userResume.getTitle() != null){
             sheet.addCell(new Label(5, 8, userResume.getTitle()));
         }
         //联系电话
         sheet.addCell(new Label(2, 9, userResume.getPhone()));
         //邮箱
         sheet.addCell(new Label(2, 10, userResume.getMail()));
      }
设置表头字体及背景颜色 
WritableFont font1 = new WritableFont(WritableFont.createFont("宋体"), 10, WritableFont.BOLD, false, UnderlineStyle.NO_UNDERLINE,WHITE);
 WritableCellFormat cellFormat1 = new WritableCellFormat(font1);
    newWb.setColourRGB(ORANGE, 150,150,150);
    cellFormat1.setBackground(ORANGE);
    SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmss");
    sheet.addCell(new Label(6, 1, "编号:"+df.format(System.currentTimeMillis()),cellFormat1));
最后关闭流
  fis.close();
        wb.close();
        newWb.write();
        newWb.close();
        return "/upload/excel/"+userEntity.getNickName()+"简历.xls";

最后附导出结果
sprng 导出指定模板的