Skip to content

Commit

Permalink
Fix empty fow handling in Excel reader
Browse files Browse the repository at this point in the history
  • Loading branch information
paytoncain committed Aug 23, 2024
1 parent eff4e78 commit fa669c3
Showing 1 changed file with 19 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,8 @@ public static Stream<MapWithRowNumber> read(InputStream inputStream, int sheetIn
.toList();

rows.remove(0);
return rows.stream().map(row -> {
try {
return rowToPropertyMap(row, headers);
} catch (TranslationException e) {
throw new RuntimeException(e);
}
});
return rows.stream()
.map(row -> rowToPropertyMap(row, headers));
} catch (IOException e) {
throw new RuntimeException(e);
}
Expand All @@ -40,22 +35,24 @@ public static Stream<MapWithRowNumber> read(InputStream inputStream, int sheetIn
}
}

private static MapWithRowNumber rowToPropertyMap(Row row, List<String> headers) throws TranslationException {
try {
return new MapWithRowNumber(
IntStream.range(0, headers.size()).boxed().collect(Collectors.toMap(
headers::get,
i -> new ValueWithColumnNumber(
Optional.ofNullable(row.getCell(i))
.map(Cell::getRawValue),
private static MapWithRowNumber rowToPropertyMap(Row row, List<String> headers) {
return new MapWithRowNumber(
IntStream.range(0, headers.size()).boxed().collect(Collectors.toMap(
headers::get,
i -> {
Optional<String> value = Optional.empty();
if (row.getCellCount() >= i + 1) {
value = Optional.ofNullable(row.getCell(i))
.map(Cell::getText);
}
return new ValueWithColumnNumber(
value,
i
)
)),
row.getRowNum()
);
} catch (Exception e) {
throw new TranslationException("Invalid rows in excel sheet");
}
);
}
)),
row.getRowNum()
);
}

}

0 comments on commit fa669c3

Please sign in to comment.