日期:2014-05-19 浏览次数:20953 次
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();//人品值
HSSFCell c = row.getCell(8);
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();
}
}
}
------解决方案--------------------
取得cell值时要判断类型。
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 那就在去数组值的时候 转换一下