Skip to content

Commit

Permalink
fix[storage]: Excel has some empty cells that cause column shifts
Browse files Browse the repository at this point in the history
  • Loading branch information
jaysunxiao committed Nov 21, 2023
1 parent dbe4766 commit 5648ebd
Showing 1 changed file with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ public static StorageData readResourceDataFromExcel(InputStream inputStream, Str
// 默认取到第一个sheet页
var sheet = wb.getSheetAt(0);
var iterator = sheet.iterator();
//设置所有列
var headers = getHeaders(iterator, resourceClassName);
// 设置所有列
var excelHeaders = getHeaders(iterator, resourceClassName);

var rows = new ArrayList<List<String>>();
while (iterator.hasNext()) {
Expand All @@ -49,13 +49,20 @@ public static StorageData readResourceDataFromExcel(InputStream inputStream, Str
}

var columns = new ArrayList<String>();
for (var header : headers) {
for (var header : excelHeaders) {
var cell = row.getCell(header.getIndex());
var content = CellUtils.getCellStringValue(cell);
columns.add(content);
}
rows.add(columns);
}

// excel某些格子空的引起的列偏移
var headers = new ArrayList<StorageHeader>();
for (var i = 0; i < excelHeaders.size(); i++) {
var excelHeader = excelHeaders.get(i);
headers.add(StorageHeader.valueOf(excelHeader.getName(), excelHeader.getType(), i));
}
return StorageData.valueOf(resourceClassName, headers, rows);
}

Expand Down

0 comments on commit 5648ebd

Please sign in to comment.