有关Cell[]溢出的问题
来源:互联网 发布:mysql字符串怎么索引 编辑:程序博客网 时间:2024/05/01 21:03
今天遇到了一个有关Excel文件导入到数据库时Cell[]的长度不固定的问题。
部分代码如下
for (int i = 0; i < sheets.length; ++i) {
System.out.println("sheet getRows: " + sheets[i].getRows());
for (int row = 1; row < sheets[i].getRows(); ++row) {
Cell[] cells = sheets[i].getRow(row);
System.out.println("CellsLength "+cells.length);
String userId = cells[0].getContents();
User user = userManager.getUserById(userId);
System.out.println("userID: " + userId);
if (user != null) {
continue;
} else {
System.out.println("已加入!");
user = new User();
}
String longinId = cells[1].getContents();
if (longinId != null && !"".equals(longinId.trim())) {
user.setLoginid(longinId);
} else {
System.out.println("已加入!");
ActionMessage msg = new ActionMessage(
"errors.longinIdNULL");
errors.add(ActionErrors.GLOBAL_ERROR, msg);
saveMessages(request,errors);
//this.saveDirectlyMessage(request, msg);
}
String passwd = cells[2].getContents();
if (passwd != null && !"".equals(passwd.trim())) {
user.setPasswd(passwd);
} else {
System.out.println("已加入!");
// 出错
// ActionMessage msg = new ActionMessage(
// "errors.passwdNULL");
// errors.add(ActionErrors.GLOBAL_ERROR, msg);
}
String name = cells[3].getContents();
if (name != null && !"".equals(name.trim())) {
user.setName(name);
} else {
System.out.println("已加入!");
// 出错
// ActionMessage msg = new ActionMessage("errors.nameNULL");
// errors.add(ActionErrors.GLOBAL_ERROR, msg);
}
String gender = cells[4].getContents();
if (gender != null && !"".equals(gender.trim())) {
// 验证是Byte
user.setGender(Byte.valueOf(gender));
} else {
}
String identitycard = cells[5].getContents();
if (identitycard != null && !"".equals(identitycard.trim())) {
user.setIdentitycard(identitycard);
} else {
}
String unitId = cells[6].getContents();
if (unitId != null && !"".equals(unitId.trim())) {
// 验证为整形
UnitInfo unitInfo = unitManager.getUnitByID(Integer
.valueOf(unitId));
user.setUnitInfo(unitInfo);
} else {
// ActionMessage msg = new ActionMessage(
// "errors.unitIDNULL");
// errors.add(ActionErrors.GLOBAL_ERROR, msg);
}
String telephone = cells[7].getContents();
if (telephone != null && !"".equals(telephone.trim())) {
user.setTelephone(telephone);
} else {
}
String email = cells[8].getContents();
if (email != null && !"".equals(email.trim())) {
// 验证格式
user.setEmail(email);
} else {
}
String descn = cells[9].getContents();
if (descn != null && !"".equals(descn.trim())) {
user.setDescn(descn);
} else {
}
String comment = cells[10].getContents();
if (comment != null && !"".equals(comment.trim())) {
user.setComment(comment);
} else {
}
}
其中因为在Excel文件中部分数据段时为空的,使得每次读出一行(对应一个用户信息)cells.length不一样。
因而有时会出现数组溢出的错误。感觉很蹊跷。
- 有关Cell[]溢出的问题
- 有关字符溢出的问题
- iOS--有关自定义Cell细线的问题
- 有关java内存溢出问题
- eclipse有关内存溢出的问题修改集合
- 有关数据溢出的总结
- 解决tomcat内存溢出有关问题
- matlab中有关cell的详细讲解
- 有关自定义等高的cell方法
- cell的重用问题
- 彻底解决Android因加载多个大图引起的OutOfMemoryError,内存溢出的有关问题
- 有关RP的table-layout以及表格文字溢出问题小结
- 有关栈溢出漏洞的利用
- 整数溢出的问题
- bitmap溢出的问题
- jboss的溢出问题
- int溢出的问题
- 缓冲区溢出的问题
- 我想要的生活
- VC字符串转换
- 制作可执行的JAR文件(适用于各种平台,在UNIX上测试通过)
- 利用Reflect显示bean数据
- WinRunner测试设计(0)
- 有关Cell[]溢出的问题
- 喜欢编程,却讨厌面对电脑,哎~,也许是不喜欢这样的生活
- Linux下登录windown系统远程桌面(3389)(转)
- 我的毕业设计
- Java 编程技术中汉字问题的分析及解决
- 整理的oracle数据库分页存储过程及示例
- 在asp中调用存储过程的几种方法
- 毕业将至,何去何从?
- 用脚本查看某库中每个表大小