excel hssf解析

public HttpCode importDeptExcel(ArrayList<String> list) throws FileNotFoundException, IOException {
long parent = Long.parseLong(list.get(0));
POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream(list.get(1)));
HSSFWorkbook wb = new HSSFWorkbook(fs);
HSSFSheet sheet = wb.getSheetAt(0);
int trLength = sheet.getLastRowNum();// 总行数
for (int rowNum = 1; rowNum < sheet.getPhysicalNumberOfRows(); rowNum++) {
HSSFRow row = sheet.getRow(rowNum);
HSSFCell d1 = row.getCell(0);// 组织姓名
HSSFCell d2 = row.getCell(1);// 组织类别
HSSFCell d3 = row.getCell(2);// 所属组织
HSSFCell d4 = row.getCell(3);// 所在单位
HSSFCell d5 = row.getCell(4);// 组织性质
HSSFCell d6 = row.getCell(5);// 建立日期
HSSFCell d7 = row.getCell(6);// 联系人
HSSFCell d8 = row.getCell(7);// 联系电话
HSSFCell d9 = row.getCell(8);// 手机号码
HSSFCell d10 = row.getCell(9);// 通讯地址
HSSFCell d11 = row.getCell(10);// 邮箱
HSSFCell d12 = row.getCell(11);// 简介
SysDept sysdept = new SysDept();
sysdept.setDeptName(getCell(d1));
// 组织类别
Map<String, String> types = sysDicService.queryDicByType("DEPTTYPE");
for (String st : types.keySet()) {
if (getCell(d2).equals(types.get(st))) {
// 获取code_
sysdept.setDeptType(st);
}
}
sysdept.setParentName(getCell(d3));
sysdept.setParentName(getCell(d4));
// 性质
Map<String, String> ty = sysDicService.queryDicByType("ORGPROPERTY");
for (String st : ty.keySet()) {
if (getCell(d5).equals(ty.get(st))) {
// 获取code_
sysdept.setDept_proper(st);
}
}
sysdept.setDeptCreatedate(getCell(d6));
sysdept.setLxr(getCell(d7));
sysdept.setLxPhone(getCell(d8));
// sysdept.setMobile(Integer.parseInt(d9.getStringCellValue().substring(0,d2.getStringCellValue().length()-2))+"");
sysdept.setMobile(getCell(d9));
sysdept.setAddress(getCell(d10));
sysdept.setEmail(getCell(d11));
sysdept.setRemark(getCell(d12));
sysdept.setParentId(parent);
HttpCode code = updateDept(sysdept);
if (code.toString() != "200") {
return HttpCode.INTERNAL_SERVER_ERROR;
}
return HttpCode.OK;


}
return HttpCode.INTERNAL_SERVER_ERROR;
}


// 根据excel类型判断
public String getCell(HSSFCell cell) {
DecimalFormat df = new DecimalFormat("#");
if (cell == null)
return "";
switch (cell.getCellType()) {
case HSSFCell.CELL_TYPE_NUMERIC:
if (HSSFDateUtil.isCellDateFormatted(cell)) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
return sdf.format(HSSFDateUtil.getJavaDate(cell.getNumericCellValue())).toString();
}
return df.format(cell.getNumericCellValue());
case HSSFCell.CELL_TYPE_STRING:
// System.out.println(cell.getStringCellValue());
return cell.getStringCellValue();
case HSSFCell.CELL_TYPE_FORMULA:
return cell.getCellFormula();
case HSSFCell.CELL_TYPE_BLANK:
return "";
case HSSFCell.CELL_TYPE_BOOLEAN:
return cell.getBooleanCellValue() + "";
case HSSFCell.CELL_TYPE_ERROR:
return cell.getErrorCellValue() + "";
}
return "";
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值