poi excel导入 数字自动加小数点
问题:导入excel表,若表格中为整数数字,不管单元格设置成数字格式还是文本格式,导入时都会出现小数点和0。
我遇到的问题是:一个名称,做测试数据的时候做了纯整形数字,发现了这个问题。
解决办法:在代码中判断,格式化一下。
/**
* 处理导入小数点
*/
public static String numOfImport(HSSFCell cell) {
String value = cell.toString();
int i = cell.getCellType();
if (i == 1) {//字符串类型
return value;
} else {
String[] str = value.split("\\.");
if (str.length > 1) {
String str1 = str[1];
int m = Integer.parseInt(str1);
if (m == 0) {
return str[0];
} else {
return value;
}
}else{
return value;
}
}
}
ps补注:最近发现还有另一种方式:
/**
* 处理导入小数点
*/
public static String numOfImport(Cell cell) {
if (cell == null) {
return "";
}
String value = cell.toString();
int i = cell.getCellType();
if (i == 1) {//字符串类型
return value;
} else {
value = def.format(cell.getNumericCellValue());
return value;
}
}
posted on 2018-07-26 14:52 qiujiababy 阅读(8727) 评论(0) 收藏 举报
浙公网安备 33010602011771号