260612_05_ENH: 엑셀 날짜 값 읽는 부분 포맷 지정
This commit is contained in:
@@ -4,7 +4,7 @@ plugins {
|
||||
}
|
||||
|
||||
// 버전 변경은 여기서
|
||||
def commonVer = "beta.1.1.28"
|
||||
def commonVer = "beta.1.1.29"
|
||||
|
||||
group = 'com.kri.common'
|
||||
version = commonVer
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.kri.common.feature.excel;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import org.apache.poi.ss.usermodel.Cell;
|
||||
import org.apache.poi.ss.usermodel.CellType;
|
||||
import org.apache.poi.ss.usermodel.CellValue;
|
||||
@@ -10,6 +11,10 @@ import org.apache.poi.ss.util.NumberToTextConverter;
|
||||
|
||||
public final class ExcelUtil {
|
||||
|
||||
private static final double TIME_FRACTION_EPSILON = 0.0000001;
|
||||
private static final String DATE_FORMAT = "yyyy-MM-dd";
|
||||
private static final String DATE_TIME_FORMAT = "yyyy-MM-dd HH:mm:ss";
|
||||
|
||||
private ExcelUtil() {
|
||||
}
|
||||
|
||||
@@ -76,13 +81,15 @@ public final class ExcelUtil {
|
||||
|
||||
private static String formatNumericCell(Cell cell, double value, DataFormatter formatter) {
|
||||
if (DateUtil.isCellDateFormatted(cell)) {
|
||||
return formatter.formatRawCellContents(
|
||||
value,
|
||||
cell.getCellStyle().getDataFormat(),
|
||||
cell.getCellStyle().getDataFormatString()
|
||||
);
|
||||
String pattern = hasTimeFraction(value) ? DATE_TIME_FORMAT : DATE_FORMAT;
|
||||
return new SimpleDateFormat(pattern).format(DateUtil.getJavaDate(value));
|
||||
}
|
||||
|
||||
return NumberToTextConverter.toText(value);
|
||||
}
|
||||
|
||||
private static boolean hasTimeFraction(double value) {
|
||||
double fraction = value - Math.floor(value);
|
||||
return fraction > TIME_FRACTION_EPSILON && (1 - fraction) > TIME_FRACTION_EPSILON;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user