部分代码片段
<!--导出导入 excel--> <dependency> <groupId>org.apache.poi</groupId> <artifactId>poi-ooxml</artifactId> <version>3.12</version> </dependency> <!--jxls导出依赖jar包--> <dependency> <groupId>net.sf.jxls</groupId> <artifactId>jxls-core</artifactId> <version>1.0.6</version> <scope>compile</scope> </dependency>
//region 导出 String filePath = systemDir + staticFileBasePath + "/评审专家注册登记表_YJY.xls"; if(UserInfo.getExpertPageMode() != null && UserInfo.getExpertPageMode() == 2){ filePath = systemDir + staticFileBasePath + "/评审专家注册登记表.xls"; } fileInput = new FileInputStream(filePath); is = new BufferedInputStream(fileInput); List<String> sheetList = new ArrayList<String>();//工作表名称 sheetList.add("Sheet1"); LocalDateTime now = LocalDateTime.now(); List<Map<String,Object>> parmsList = new ArrayList<>();//入参 Map<String,Object> map = new HashMap<>(); map.put("year",now.getYear()); map.put("month",now.getMonth().getValue()); map.put("day",now.getDayOfMonth()); map.put("name",NAME); map.put("idCard",ID_CARD); map.put("phone",PHONE); map.put("sex",sex); map.put("adress",POSTAL_ADDRESS); map.put("email",E_MAIL); map.put("industry",work); map.put("wrokYear",START_WORK_DATE_YEAR); map.put("highDegree",HIGH_DEGREE); map.put("graduateSchool",GRADUATE_SCHOOL); map.put("industryTxt",INDUSTRY_ID_TXT); map.put("levelTxt",LEVEL_ID_TXT); map.put("org",ORG); map.put("aviodUnit",AVIOD_UNIT); map.put("registType",REGISTRATION_TYPE); map.put("registSource",ZFCG_SOURCE); map.put("mainTxt",mainStr); map.put("elseTxt",elseStr); map.put("zjType",ZjType); map.put("major",MAJOR_TXT); map.put("healath",HEALTH); parmsList.add(map); XLSTransformer transformer = new XLSTransformer(); HSSFWorkbook workbook = (HSSFWorkbook) transformer.transformMultipleSheetsList(is, parmsList,sheetList,"expert",new HashMap(),0); //region 特殊单元格处理 HSSFSheet hssfSheet = workbook.getSheet("Sheet1"); if(UserInfo.getExpertPageMode() != null && UserInfo.getExpertPageMode()==2){ //在职情况 if(StringUtils.isNotEmpty(work)){ HSSFCell cell7 = hssfSheet.getRow(7).getCell(2); HSSFCellStyle cellStyle7 = cell7.getCellStyle();//获取单元格样式 cellStyle7.setAlignment(HSSFCellStyle.ALIGN_CENTER); //水平居中 cellStyle7.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);//垂直居中 if("在职".equals(work)){ cell7.setCellValue("☑在职 □离职"); }else{ cell7.setCellValue("□在职 ☑离职"); } } //登记类型 if(StringUtils.isNotEmpty(REGISTRATION_TYPE)){ HSSFCell cell12 = hssfSheet.getRow(12).getCell(2); HSSFCellStyle cellStyle12 = cell12.getCellStyle();//获取单元格样式 cellStyle12.setAlignment(HSSFCellStyle.ALIGN_CENTER); //水平居中 cellStyle12.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);//垂直居中 if("1".equals(REGISTRATION_TYPE)){ cell12.setCellValue("☑新注册专家 □已获得有关政府部门的评审专家资格认定"); }else { cell12.setCellValue("□新注册专家 ☑已获得有关政府部门的评审专家资格认定"); } } } //endregion response.setHeader("content-disposition", "attachment; filename=" + URLEncoder.encode(fileName, "UTF-8")); response.setContentType("application/msexcel"); os = response.getOutputStream(); workbook.write(os); //endregion
excel模板
标签:map,java,excel,cell12,HSSFCellStyle,put,new,now,模板 From: https://www.cnblogs.com/privateLogs/p/17620508.html