ZP 修改内容:
1.导入时如果遇到空行可能会出现空指针异常 2.导入时对于带有小数部分得数据可能出现精度丢失得情况,修改后精确到小数点后两位,此处应该可以根据实际情况来配置,或者其他更加好的方法,比如保留所有进度
This commit is contained in:
thinkgem
2018-04-23 19:36:51 +08:00
parent fb0e94fe6d
commit 3ca1bd53e7

View File

@@ -194,6 +194,9 @@ public class ExcelImport {
*/
public Row getRow(int rownum){
Row row = this.sheet.getRow(rownum);
if (row == null){
return null;
}
// 验证是否是空行如果空行返回null
short cellNum = 0;
short emptyNum = 0;
@@ -254,11 +257,15 @@ public class ExcelImport {
if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC){
val = cell.getNumericCellValue();
if (HSSFDateUtil.isCellDateFormatted(cell)) {
val = DateUtil.getJavaDate((Double)val); // POI Excel 日期格式转换
}else{
val = new DecimalFormat("0").format(val);
}
}else if (cell.getCellType() == Cell.CELL_TYPE_STRING){
val = DateUtil.getJavaDate((Double) val); // POI Excel 日期格式转换
}else{
if ((Double) val % 1 > 0){
val = new DecimalFormat("0.00").format(val);
}else{
val = new DecimalFormat("0").format(val);
}
}
}else if (cell.getCellType() == Cell.CELL_TYPE_STRING) {
val = cell.getStringCellValue();
}else if (cell.getCellType() == Cell.CELL_TYPE_FORMULA){
try {
@@ -481,7 +488,7 @@ public class ExcelImport {
// Object val = ei.getCellValue(row, j);
// System.out.print(val+", ");
// }
// System.out.print("\n");
// System.out.println();
// }
//
// }