使用POI 读取 Excel 文件,读取手机号码 变成 1.3471022771E10

时间:2023-03-09 16:21:42
使用POI 读取 Excel 文件,读取手机号码 变成 1.3471022771E10

使用POI 读取 Excel 文件,读取手机号码 变成 1.3471022771E10 [问题点数:40分,结帖人xieyongqiu]

           
不显示删除回复
           
显示所有回复
           
显示星级回复
           
显示得分回复
           
只显示楼主
          使用POI 读取 Excel 文件,读取手机号码 变成 1.3471022771E10收藏
关注
xieyongqiu
maobingxixi
本版等级:使用POI 读取 Excel 文件,读取手机号码 变成 1.3471022771E10
结帖率:71.43%
楼主发表于: 2010-09-13 17:33:03

使用POI 读取 Excel 文件,读取手机号码 变成  1.3471022771E10   如何 解决?

更多2分享到:

回复次数:15

关注
eemean
eemean
本版等级:
#1 得分:5回复于: 2010-09-13 17:34:34
你要多判断一下,CELL TYPE好像有四种类型的,,
关注
xieyongqiu
maobingxixi
本版等级:
#2 得分:0回复于: 2010-09-13 17:41:35
   
   if (cell.getCellType() == HSSFCell.CELL_TYPE_NUMERIC) {

DateFormat format = new SimpleDateFormat(DateUtil.YYYY_MM_DD);

if(HSSFDateUtil.isCellDateFormatted(cell)) {
     // 是否为日期型
      str = format.format(cell.getDateCellValue());
    } else {
     // 是否为数值型
      double d = cell.getNumericCellValue();
     if (d - (int) d < Double.MIN_VALUE) { 
     // 是否为int型
      str = Integer.toString((int) d);
     } else { 
      System.out.println("double.....");
      // 是否为double型
      str = Double.toString(cell.getNumericCellValue());
     }
    }
 
   System.out.println("type=="+cell.getCellType() );
   System.out.println("cell=="+str);

}else if (cell.getCellType() == HSSFCell.CELL_TYPE_STRING) {
str = cell.getRichStringCellValue().getString();
}else if (cell.getCellType() == HSSFCell.CELL_TYPE_FORMULA) {
 str = cell.getCellFormula();
}else if (cell.getCellType() == HSSFCell.CELL_TYPE_BLANK) {
 str = " ";
}else if (cell.getCellType() == HSSFCell.CELL_TYPE_ERROR) {
 str = " ";
}

这几种 类型  都做判断了   依然还是    1.3471022771E10

关注
xieyongqiu
maobingxixi
本版等级:使用POI 读取 Excel 文件,读取手机号码 变成 1.3471022771E10
#3 得分:0回复于: 2010-09-13 17:51:55
 解决了    是一个转换问题

//将被表示成1.3922433397E10的手机号转化为13922433397,不一定是最好的转换方法
  DecimalFormat df = new DecimalFormat("#");

System.out.println("type666=="+df.format(cell.getNumericCellValue()));