利用jxl操作Excel(二)
程序员文章站
2022-03-11 12:05:22
...
导入数据
List<UserInfo> userInfoList = new ArrayList<UserInfo>();
Workbook book = Workbook.getWorkbook(excel);
Sheet sheet = book.getSheet(0);
int row = sheet.getRows();
for (int i = 1; i < row; i++) {
UserInfo userInfo = new UserInfo();
//获取数据
userInfo.setUserId(0);
userInfo.setUserName(sheet.getCell(0, i).getContents());
userInfo.setUserPassword(sheet.getCell(1, i).getContents());
//检测是否存在相同的用户名
//UserId=1 Conflict Excel内部重复
if (userInfoList.size() != 0){
for (int iUserName=0; iUserName<userInfoList.size(); iUserName++){
if (userInfo.getUserName().toUpperCase().equals(userInfoList.get(iUserName).getUserName().toUpperCase())){
userInfoList.get(iUserName).setUserId(1);
userInfo.setUserId(1);
}
}
}
//检测是否存在相同的用户名
//UserId=2 Exist 数据库内部重复
List<UserInfo> userInfoListExist = new ArrayList<UserInfo>();
userInfoListExist = userInfoDao.findByUserName(userInfo.getUserName());
if (userInfoListExist.size() == 0 || userInfo.getUserId() == 1){
userInfoList.add(userInfo);
}else{
userInfo.setUserId(2);
userInfoList.add(userInfo);
}
}
上一篇: 莴笋可以隔夜吃吗?