导入Excel

来源:互联网 发布:手机qq变声软件 编辑:程序博客网 时间:2024/05/22 02:16

Action :

public Reply readExcel() {
File file = _getFileOne(); //获取上传的excel文件
String fileName = new SimpleDateFormat("yyyyMMddHHmmss")
.format(Calendar.getInstance().getTime())+UUID.randomUUID()+".xls";
Workbook wb;  //  工作薄
try {
wb = WorkbookFactory.create(file);
Sheet sheet = wb.getSheetAt(0);  //获取工作表
for(int i=1;i<=sheet.getLastRowNum();i++){
Row row = sheet.getRow(i);  //获取行数据
Cell idCell = row.getCell(0);  //获取 当前行的 某一单元格
//返回服务费 付费状态
Cell payStatusCell = row.getCell(14);
Map<String,Object> map = new HashMap<String, Object>();
if(idCell!=null){
double id = idCell.getNumericCellValue();
map.put("ID",id);
}
if(payStatusCell!=null){
String payStatus = payStatusCell.getStringCellValue();
System.out.println(payStatus+"--------bb---------"+map.get("ID"));
if("成功".equals(payStatus)){
map.put("STATUS", 2);
map.put("TYPE", 2);
}else if("失败".equals(payStatus)){
map.put("STATUS", 3);
map.put("TYPE", 1);
}
System.out.println(map+"--------");
service.updateServiceFeeStatus(map);  //修改数据库信息
}
}
String filePath = SkyEye.getConfig("file.path")+File.separator+"serviceFee";
BaseUtil.createDirectory(filePath);
File file2 = new File(filePath+File.separator+fileName);
System.out.println(filePath+"----path----");
FileCopyUtils.copy(file, file2);
} catch (InvalidFormatException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return new ReplyAjax(true, "成功").addOp(new OpLog("贷后管理","返佣管理",
"导入文件名:"+fileName+",导入时间:"+new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
.format(new Date())));
}

0 0
原创粉丝点击