From 00d836c9a224c78fb0cf89d3f2b69ab05c28cff8 Mon Sep 17 00:00:00 2001 From: jhjang <jhjang@maprex.co.kr> Date: 화, 08 2월 2022 09:55:05 +0900 Subject: [PATCH] - 임포트 날짜 코드 예외처리 추가 --- src/main/java/kr/wisestone/owl/service/impl/IssueServiceImpl.java | 10 ++++++++-- src/main/java/kr/wisestone/owl/util/CommonUtil.java | 24 +++++++++++++++--------- src/main/java/kr/wisestone/owl/util/DateUtil.java | 1 + 3 files changed, 24 insertions(+), 11 deletions(-) diff --git a/src/main/java/kr/wisestone/owl/service/impl/IssueServiceImpl.java b/src/main/java/kr/wisestone/owl/service/impl/IssueServiceImpl.java index 45418f0..78e3448 100644 --- a/src/main/java/kr/wisestone/owl/service/impl/IssueServiceImpl.java +++ b/src/main/java/kr/wisestone/owl/service/impl/IssueServiceImpl.java @@ -3471,8 +3471,13 @@ */ private Boolean cellNullCheck (Cell cell) { if (cell != null ) { - if (cell.getCellType() != Cell.CELL_TYPE_BLANK) { - if (cell.getCellType() == Cell.CELL_TYPE_STRING && cell.getStringCellValue() != null) { + int cellType = cell.getCellType(); + if (cellType < Cell.CELL_TYPE_BLANK) { + if (cellType == Cell.CELL_TYPE_STRING) + { + if (cell.getStringCellValue() != null) + return false; + } else { return false; } } @@ -3499,6 +3504,7 @@ boolean isNull = cellNullCheck(cell); String cellStr = ""; + if (!isNull) { cellStr = CommonUtil.convertExcelStringToCell(cell); diff --git a/src/main/java/kr/wisestone/owl/util/CommonUtil.java b/src/main/java/kr/wisestone/owl/util/CommonUtil.java index af20eb8..801fff6 100644 --- a/src/main/java/kr/wisestone/owl/util/CommonUtil.java +++ b/src/main/java/kr/wisestone/owl/util/CommonUtil.java @@ -12,6 +12,7 @@ import org.apache.commons.codec.binary.Base64; import org.apache.commons.lang3.RandomStringUtils; import org.apache.commons.lang3.StringUtils; +import org.apache.poi.hssf.usermodel.HSSFDateUtil; import org.apache.poi.ss.usermodel.Cell; import org.jsoup.Jsoup; import org.slf4j.Logger; @@ -960,17 +961,22 @@ switch (cell.getCellType()) { case Cell.CELL_TYPE_NUMERIC : - double doubleValue = cell.getNumericCellValue(); - int intValue; + if (HSSFDateUtil.isCellDateFormatted(cell)) { + Date date = cell.getDateCellValue(); + cellValue = DateUtil.convertDateToStr(date, "yyyy-MM-dd hh:mm:ss"); - if (doubleValue % 1 == 0) { - intValue = (int)doubleValue; - cellValue = intValue + ""; - } - else { - cellValue = doubleValue + ""; - } + } else { + double doubleValue = cell.getNumericCellValue(); + int intValue; + if (doubleValue % 1 == 0) { + intValue = (int)doubleValue; + cellValue = intValue + ""; + } + else { + cellValue = doubleValue + ""; + } + } break; case Cell.CELL_TYPE_STRING : diff --git a/src/main/java/kr/wisestone/owl/util/DateUtil.java b/src/main/java/kr/wisestone/owl/util/DateUtil.java index ab66168..47fe136 100644 --- a/src/main/java/kr/wisestone/owl/util/DateUtil.java +++ b/src/main/java/kr/wisestone/owl/util/DateUtil.java @@ -62,6 +62,7 @@ public static String convertDateToStr(Date source, String pattern, Locale locale) { String date = null; + SimpleDateFormat sdf = new SimpleDateFormat(pattern, locale); date = sdf.format(source); -- Gitblit v1.8.0