读书人

POI解析excel2007整形数据有关问题求

发布时间: 2013-12-15 22:17:18 作者: rapoo

POI解析excel2007整形数据问题,在线等,急求
在excel2007里面数据是1001(整形),但是在解析后取到的判断确实1001.0,所以在判断的时候就判断是小数点做处理了。
下面是这个循环判断的类型获取方式代码:

 case XSSFCell.CELL_TYPE_NUMERIC:
// System.out.println(i+"行"+j+" 列 is Number type ; DateFormt:"+cell.getCellStyle().getDataFormatString());
if("@".equals(cell.getCellStyle().getDataFormatString())){
value = df.format(cell.getNumericCellValue());
} else if("General".equals(cell.getCellStyle().getDataFormatString())){
value = nf.format(cell.getNumericCellValue());
}else{
value = sdf.format(HSSFDateUtil.getJavaDate(cell.getNumericCellValue()));
}

我觉得应该是
"@".equals(cell.getCellStyle().getDataFormatString())
成立的,到那时应为获取到的时候多了一个.0所以走了第2个表达式。有大神告知下是什么原因啊?需要在excel里面做格式限定吗? 但是我excel不怎么会弄,第一行必须是有一行标题的? 急求,在线等啊!!!!
[解决办法]
我恰好也是遇见这个问题,我觉得这个人写的不错。http://my.oschina.net/u/140625/blog/59288
本人也采用了他的方法,加入了这些这样的就搞定了
case XSSFCell.CELL_TYPE_NUMERIC:
Double cellValue_dob = cell.getNumericCellValue();
str[i][j] = cellValue_dob.toString().substring(0, cellValue_dob.toString().length() - 2);
break;

读书人网 >OFFICE教程

热点推荐