diff --git a/excel-importer-test/src_test/com/axonivy/util/excel/test/TestExcelReader.java b/excel-importer-test/src_test/com/axonivy/util/excel/test/TestExcelReader.java index 1d6fe91..16d669f 100644 --- a/excel-importer-test/src_test/com/axonivy/util/excel/test/TestExcelReader.java +++ b/excel-importer-test/src_test/com/axonivy/util/excel/test/TestExcelReader.java @@ -4,7 +4,7 @@ import java.io.IOException; import java.nio.file.Path; -import java.sql.Timestamp; +import java.util.Date; import java.util.List; import org.apache.poi.ss.usermodel.Workbook; import org.junit.jupiter.api.Test; @@ -25,7 +25,7 @@ void parseColumns_xlsx(@TempDir Path dir) throws IOException { .contains("Firstname", "Lastname"); assertThat(columns).contains( new Column("Firstname", String.class, 255), new Column("ZIP", Integer.class), - new Column("Amount", Double.class), new Column("Birthdate", Timestamp.class), // should be a date + new Column("Amount", Double.class), new Column("Birthdate", Date.class), // should be a date new Column("Note", String.class, 811), new Column("Column contains texts in incorrect number format", String.class, 255), new Column("Column contains both text and numeric", String.class, 255) @@ -44,4 +44,15 @@ void parseColumnsOver255Characters_xlsx(@TempDir Path dir) throws IOException { new Column("Summary", String.class, 823)); } + @Test + void parseColumnsSeveralDateFormats_xlsx(@TempDir Path dir) throws IOException { + Path path = dir.resolve("customers.xlsx"); + TstRes.loadTo(path, "sample_date_format.xlsx"); + Workbook wb = ExcelLoader.load(path); + List columns = ExcelReader.parseColumns(wb.getSheetAt(0)); + assertThat(columns).extracting(Column::getName).contains("Start date", "End date", "Date without year"); + assertThat(columns).contains(new Column("Start date", Date.class), + new Column("End date", Date.class), new Column("Date without year", Date.class)); + } + } diff --git a/excel-importer-test/src_test/com/axonivy/util/excel/test/sample_date_format.xlsx b/excel-importer-test/src_test/com/axonivy/util/excel/test/sample_date_format.xlsx new file mode 100644 index 0000000..fed09ec Binary files /dev/null and b/excel-importer-test/src_test/com/axonivy/util/excel/test/sample_date_format.xlsx differ diff --git a/excel-importer/src/com/axonivy/util/excel/importer/ExcelReader.java b/excel-importer/src/com/axonivy/util/excel/importer/ExcelReader.java index 1300ae1..3119074 100644 --- a/excel-importer/src/com/axonivy/util/excel/importer/ExcelReader.java +++ b/excel-importer/src/com/axonivy/util/excel/importer/ExcelReader.java @@ -1,12 +1,12 @@ package com.axonivy.util.excel.importer; -import java.sql.Timestamp; import java.text.DecimalFormat; import java.util.ArrayList; import java.util.Iterator; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import java.util.Date; import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.StringUtils; @@ -65,7 +65,7 @@ private static Column toColumn(String fieldName, Cell cell) { switch (cell.getCellType()) { case NUMERIC: if (DateUtil.isCellDateFormatted(cell)) { - return new Column(fieldName, Timestamp.class); + return new Column(fieldName, Date.class); } if (CellUtils.isInteger(cell)) { return new Column(fieldName, Integer.class);