Skip to content

Commit

Permalink
fix: define type as string, if first row has no data
Browse files Browse the repository at this point in the history
  • Loading branch information
ivy-rew committed Oct 25, 2023
1 parent 5179cab commit 22b2d67
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ void readGermanized(@TempDir Path dir) throws Exception {
assertThat(entity.getField("anzahlInneresBehltnis").getComment())
.as("preserve real column names")
.isEqualTo("Anzahl Inneres Behältnis");

assertThat(entity.getField("zulassungsinhaberName").getType())
.isEqualTo(String.class.getName());
assertThat(entity.getField("pNRZulassungsinhaber").getType())
.isEqualTo(Double.class.getName());
}

@BeforeEach
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import java.util.List;

import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;

Expand Down Expand Up @@ -36,20 +35,19 @@ private static List<Column> createEntityFields(List<String> names, Iterator<Row>
return List.of();
}
Row row = rowIterator.next();
Iterator<Cell> cellIterator = row.cellIterator();
int cellNo = 0;
while (cellIterator.hasNext()) {
Cell cell = cellIterator.next();
var name = names.get(cellNo);
var column = toColumn(name, cell.getCellType());
for(int c = 0; c<row.getLastCellNum(); c++) {
var name = names.get(c);
var column = toColumn(name, row.getCell(c));
columns.add(column);
cellNo++;
}
return columns;
}

private static Column toColumn(String name, CellType type) {
switch (type) {
private static Column toColumn(String name, Cell cell) {
if (cell == null) {
return new Column(name, String.class); // type not known on first row
}
switch (cell.getCellType()) {
case NUMERIC:
return new Column(name, Double.class);
case STRING:
Expand Down

0 comments on commit 22b2d67

Please sign in to comment.