Skip to content

Commit

Permalink
MARP-1315 Excel Importer: Solution for adding cells with more than 25…
Browse files Browse the repository at this point in the history
…5 chars (#66)
  • Loading branch information
tvtphuc-axonivy authored Nov 6, 2024
1 parent 7a1ecc5 commit 76ceb71
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<Column> 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));
}

}
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 76ceb71

Please sign in to comment.