excel 数据格式如下:
姓名* 学号* 省份证号* 城市 卡号 人品值
------------------------------------------------------------------------------
李爱你 43QW 12121221 1 1 好的
java代码: sheet.getCellComment(0, i) ;
Row row = (Row) sheet.getRow(i);
StudentDto student = new StudentDto();
//获取用户信息
String name = row.getCell(0).getRichStringCellValue().toString();//姓名
String code = row.getCell(1).getRichStringCellValue().toString();//学号
String idCard = row.getCell(2).getRichStringCellValue().toString();//身份证
String instidute = row.getCell(3).getRichStringCellValue().toString();//城市
String major = row.getCell(4).getRichStringCellValue().toString();//卡号
String state = row.getCell(5).getRichStringCellValue().toString();//人品值如上内容出现这样的情况:
当我取excle 姓名 和 学号都是OK 的 。 但是 当我取 城市 和卡号 的时候都会报错 。
我把 城市 和 卡号 改成: 1a 和 1b 的时候 又不会报错 。说到底 就是 去excle里面的整形 数据就会报错。为什么。大侠 救命 小弟分全给你。
姓名* 学号* 省份证号* 城市 卡号 人品值
------------------------------------------------------------------------------
李爱你 43QW 12121221 1 1 好的
java代码: sheet.getCellComment(0, i) ;
Row row = (Row) sheet.getRow(i);
StudentDto student = new StudentDto();
//获取用户信息
String name = row.getCell(0).getRichStringCellValue().toString();//姓名
String code = row.getCell(1).getRichStringCellValue().toString();//学号
String idCard = row.getCell(2).getRichStringCellValue().toString();//身份证
String instidute = row.getCell(3).getRichStringCellValue().toString();//城市
String major = row.getCell(4).getRichStringCellValue().toString();//卡号
String state = row.getCell(5).getRichStringCellValue().toString();//人品值如上内容出现这样的情况:
当我取excle 姓名 和 学号都是OK 的 。 但是 当我取 城市 和卡号 的时候都会报错 。
我把 城市 和 卡号 改成: 1a 和 1b 的时候 又不会报错 。说到底 就是 去excle里面的整形 数据就会报错。为什么。大侠 救命 小弟分全给你。
解决方案 »
- J2EE求帮助。一直在看马士兵的视频 觉得J2SE学的还可以了。就开始学J2EE。
- Exception in thread "main" javax.swing.text.ChangedCharSetException这个错误如何解决
- hao123最快克隆
- struts2 textfield label的问题
- java连数据库
- 请问各位大侠,为什么我的电脑不能安装J2EE SDK?
- 开发第一个Hibernate程序遇到了小麻烦,不知道怎么放这些文件与程序?
- jboss连接数据库oracle的问题
- 请问?j2ee应用服务器支持Javabean吗,我下的jspsmartupload放在上面能用吗?
- 关于一个计时的问题
- No tag "forEatch" defined in tag library imported with prefix "c"
- struts2如何在页面加载时显示数据库的值
row.getCell(3).getRichStringCellValue().toString();//城市
把toString()去掉看看。
if (c.getCellType() == HSSFCell.CELL_TYPE_STRING) {
String s = row.getCell(8).getRichStringCellValue().getString();
if (NumberUtils.isNumber(s)) {
return new Double(s);
} else {
return 0.0;
}
} else {
return row.getCell(8).getNumericCellValue();
}
Sheet sheet1 = wb.getSheetAt(0);
for (Row row : sheet1) {
for (Cell cell : row) {
CellReference cellRef = new CellReference(row.getRowNum(), cell.getColumnIndex());
System.out.print(cellRef.formatAsString());
System.out.print(" - "); switch (cell.getCellType()) {
case Cell.CELL_TYPE_STRING:
System.out.println(cell.getRichStringCellValue().getString());
break;
case Cell.CELL_TYPE_NUMERIC:
if (DateUtil.isCellDateFormatted(cell)) {
System.out.println(cell.getDateCellValue());
} else {
System.out.println(cell.getNumericCellValue());
}
break;
case Cell.CELL_TYPE_BOOLEAN:
System.out.println(cell.getBooleanCellValue());
break;
case Cell.CELL_TYPE_FORMULA:
System.out.println(cell.getCellFormula());
break;
default:
System.out.println();
}
}
}
getCellType() ==CELL_TYPE_BLANK
空值CELL_TYPE_BOOLEAN
布尔型CELL_TYPE_ERROR
错误CELL_TYPE_FORMULA
公式型CELL_TYPE_STRING
字符串型CELL_TYPE_NUMERIC
数值型
String cellStr=row.getCell(8).toString();
我导入excle到数据库里的思路是:
1.选择excle文件
2.上传到服务器
3.读excle文件,返回一个String[][]
4.数组当参数,传入数据库插入的方法里如果数据库类型是int 那就在去数组值的时候 转换一下
我用下面的代码读取excel中不同类型的数据 switch(cellType)
{
case HSSFCell.CELL_TYPE_NUMERIC:
调用getNumericCellValue();break;
case HSSFCell.CELL_TYPE_STRING:
调用getStringCellValue();break;
} 我的程序里注重的是数据的格式而不是数据的类型,我希望读取到的数据的格式能够与excel中的原始格式一致,但是getNumericCellValue()返回的是Double型,那样即使excel中是整数,使用getNumericCellValue()获得的数据也被加上了小数位。我觉得POI给我画蛇添足了。所以 二楼 哥们 三克油