大家好,项目内用到java解析Excel的功能,我的问题有两个,向大家请教:
1、用jxl只能支持读取office2003及office以前的版本,不支持office2007之后的版本读取;
2、用poi虽然能同时支持office2003和office2007之后的版本,但是poi在读取Excel的过程中会出现精度缺失的问题,如:Excel单元格中的数据原本是12,但是POI的方法读取出来之后是11.99999999999。
由于Excel读取单元格的数据之后会对数值进行校验,当出现精度缺失时校验不通过。因此,向大家请教如何解决这类问题,谢谢!
你用String 来存取数据看看 。
switch(cellType) {
case Cell.CELL_TYPE_STRING: //文本
cellValue = cell.getStringCellValue();
break;
case Cell.CELL_TYPE_NUMERIC: //数字、日期
if(DateUtil.isCellDateFormatted(cell)) {
cellValue = fmt.format(cell.getDateCellValue()); //日期型
}
else {
DecimalFormat df = new DecimalFormat("#");
//System.out.println("type666=="+df.format(cell.getNumericCellValue()));
//cellValue = String.valueOf(cell.getNumericCellValue()); //数字
cellValue =df.format(cell.getNumericCellValue());
}
break;
case Cell.CELL_TYPE_BOOLEAN: //布尔型
cellValue = String.valueOf(cell.getBooleanCellValue());
break;
case Cell.CELL_TYPE_BLANK: //空白
cellValue = cell.getStringCellValue();
break;
case Cell.CELL_TYPE_ERROR: //错误
cellValue = "错误";
break;
case Cell.CELL_TYPE_FORMULA: //公式
cellValue = "错误";
break;
default:
cellValue = "错误";
}
直接通过string就能导入进去了