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 5d0471e..1d6fe91 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 @@ -6,11 +6,9 @@ import java.nio.file.Path; import java.sql.Timestamp; import java.util.List; - import org.apache.poi.ss.usermodel.Workbook; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.io.TempDir; - import com.axonivy.util.excel.importer.Column; import com.axonivy.util.excel.importer.ExcelLoader; import com.axonivy.util.excel.importer.ExcelReader; @@ -33,5 +31,17 @@ void parseColumns_xlsx(@TempDir Path dir) throws IOException { new Column("Column contains both text and numeric", String.class, 255) ); } + + @Test + void parseColumnsOver255Characters_xlsx(@TempDir Path dir) throws IOException { + Path path = dir.resolve("customers.xlsx"); + TstRes.loadTo(path, "sample_over_255_characters.xlsx"); + Workbook wb = ExcelLoader.load(path); + List columns = ExcelReader.parseColumns(wb.getSheetAt(0)); + assertThat(columns).extracting(Column::getName).contains("FirstName", "LastName" , "Summary"); + assertThat(columns).contains(new Column("FirstName", String.class, 255), + new Column("LastName", String.class, 255), + new Column("Summary", String.class, 823)); + } } diff --git a/excel-importer-test/src_test/com/axonivy/util/excel/test/sample_over_255_characters.xlsx b/excel-importer-test/src_test/com/axonivy/util/excel/test/sample_over_255_characters.xlsx new file mode 100644 index 0000000..61eb94f Binary files /dev/null and b/excel-importer-test/src_test/com/axonivy/util/excel/test/sample_over_255_characters.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 5c9ffd4..1300ae1 100644 --- a/excel-importer/src/com/axonivy/util/excel/importer/ExcelReader.java +++ b/excel-importer/src/com/axonivy/util/excel/importer/ExcelReader.java @@ -8,6 +8,7 @@ import java.util.List; import java.util.Map; +import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.StringUtils; import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.CellType; @@ -91,7 +92,9 @@ private static void updateColumn(Column column, Cell cell) { } if (cell.getCellType() == CellType.STRING) { column.setType(String.class); - column.setDatabaseFieldLength(DEFAULT_STRING_LENGTH); + if (ObjectUtils.isEmpty(column.getDatabaseFieldLength())) { + column.setDatabaseFieldLength(DEFAULT_STRING_LENGTH); + } } if (column.getType().equals(String.class)) { var cellValue = getCellValueAsString(cell);