|
@@ -43,6 +43,60 @@ public class ExcelUtils {
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
+ public static List<List<Map<String, Object>>> read(InputStream inputStream, List<SheetReadInfo> infos, List<String> sheetNameList) {
|
|
|
+ List<List<Map<String, Object>>> answer = new ArrayList<>(infos.size());
|
|
|
+
|
|
|
+ try {
|
|
|
+ Workbook workbook = new XSSFWorkbook(inputStream);
|
|
|
+
|
|
|
+ for (int infoIndex = 0; infoIndex < infos.size(); infoIndex++) {
|
|
|
+ List<Map<String, Object>> result = new ArrayList<>();
|
|
|
+ answer.add(result);
|
|
|
+
|
|
|
+ Sheet sheet = workbook.getSheet(sheetNameList.get(infoIndex));
|
|
|
+ SheetReadInfo info = infos.get(infoIndex);
|
|
|
+ Integer startRow = info.getStartRow();
|
|
|
+ List<Integer> columnIndexs = info.getColumnIndexs();
|
|
|
+ List<String> keys = info.getColumnKeys();
|
|
|
+ List<String> types = info.getColumnTypes();
|
|
|
+
|
|
|
+ int lastRowNum = sheet.getLastRowNum();
|
|
|
+ for (int rowIndex = startRow; rowIndex < lastRowNum + 1; rowIndex++) {
|
|
|
+ Row row = sheet.getRow(rowIndex);
|
|
|
+ if (null == row) {
|
|
|
+ System.err.println("==========rowIndex:" + rowIndex);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ Map<String, Object> data = new HashMap<>();
|
|
|
+ for (int columnDefIndex = 0; columnDefIndex < columnIndexs.size(); columnDefIndex++) {
|
|
|
+ Integer columnIndex = columnIndexs.get(columnDefIndex);
|
|
|
+ String key = keys.get(columnDefIndex);
|
|
|
+ String type = types.get(columnDefIndex);
|
|
|
+ Cell cell = row.getCell(columnIndex);
|
|
|
+ if (null == cell) {
|
|
|
+ System.err.println("==========columnIndex:" + columnIndex);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ Object value = parseCell(cell, type);
|
|
|
+ if (null != value) {
|
|
|
+ data.put(key, value);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (0 < data.size()) {
|
|
|
+ data.put(info.getSeqKey(), rowIndex);
|
|
|
+ result.add(data);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ workbook.close();
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ } finally {
|
|
|
+ }
|
|
|
+ return answer;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
public static List<List<Map<String, Object>>> read(InputStream inputStream, List<SheetReadInfo> infos) {
|
|
|
List<List<Map<String, Object>>> answer = new ArrayList<>(infos.size());
|
|
|
|