Address fragility in importing spreadsheets with missing header columns

This commit is contained in:
Brendan Robert 2021-04-02 15:08:50 -05:00
parent 0be1b6fe3e
commit 269580cf11

View File

@ -116,12 +116,13 @@ public class SheetEditorControllerImpl extends SheetEditorController {
}).collect(Collectors.toCollection(editor.getSheet().getColumns()::getColumn));
editor.getSheet().setRows(new Rows());
List<String> header = data.get(0);
data.stream().skip(1)
.map(cols -> {
Row r = new Row();
for (int i = 0; i < cols.size(); i++) {
if (cols.get(i) != null) {
setValue(r.getOtherAttributes(), data.get(0).get(i), cols.get(i));
if (cols.get(i) != null && header.size() > i && header.get(i) != null) {
setValue(r.getOtherAttributes(), header.get(i), cols.get(i));
}
}
return r;