/** * 取excel单元格的日期(如果是日期格式,用Date得到;如果是文本类型,根据导出格式转成date) */ private Date getCellDate(Row row,int i){ Date date = new Date(); String strDate = ""; try{ date = row.getCell(i).getDateCellValue(); }catch(Exception e){ strDate = getCellValue(i,row); } if(!"".equals(strDate)){ date = DateUtils.String2Date(StringUtils.replaceNull2Space(strDate), "yyyy-MM-dd HH:mm:ss"); } return date; } /** * 去通用代码,通过name取code */ private String getCodeByName(String type , String name){ String sql = "select t.Lookup_Code from sys_lookup_vl t where t.Lookup_Type = '" + type +"' and t.Lookup_Name = '" +name+ "'"; List list = this.getHibernateDAO().findBySql(sql); if(null != list && list.size() > 0){ return ComUtil.replaceObjectToStr(list.get(0)[0]); }else{ return ""; } } // 取单元格值的通用方法 private String getCellValue(int i, Row row) { String name = ""; if(row.getCell(i) == null){ return name; } if (row.getCell(i).getCellType() == HSSFCell.CELL_TYPE_NUMERIC) { name = row.getCell(i).getNumericCellValue() + ""; if(name.endsWith(".0")){ name = name.substring(0, name.length()-2).trim(); } } else if (row.getCell(i).getCellType() == HSSFCell.CELL_TYPE_STRING) { name = row.getCell(i).getStringCellValue().trim(); } return name; }
java excel通用导入类_java中excel导入各种类型取值
最新推荐文章于 2023-03-11 22:55:36 发布