|
@@ -4,6 +4,7 @@ import cn.hutool.core.collection.ListUtil;
|
|
|
import com.alibaba.excel.context.AnalysisContext;
|
|
|
import com.alibaba.excel.event.AnalysisEventListener;
|
|
|
import com.alibaba.excel.read.metadata.holder.ReadSheetHolder;
|
|
|
+import com.simuwang.base.pojo.dto.report.CustomExcelTable;
|
|
|
import com.simuwang.base.pojo.dto.report.SimpleTable;
|
|
|
|
|
|
import java.util.LinkedHashMap;
|
|
@@ -14,7 +15,7 @@ import java.util.List;
|
|
|
* @date 2024/10/12 9:17
|
|
|
* @description 自定义的excel多sheet解析事件监听器
|
|
|
*/
|
|
|
-public class CustomExcelMultiSheetListener extends AnalysisEventListener<LinkedHashMap<String, Object>> {
|
|
|
+public class CustomExcelMultiSheetListener extends AnalysisEventListener<LinkedHashMap<Integer, Object>> {
|
|
|
private final List<SimpleTable> tables = ListUtil.list(false);
|
|
|
private SimpleTable table;
|
|
|
|
|
@@ -27,25 +28,33 @@ public class CustomExcelMultiSheetListener extends AnalysisEventListener<LinkedH
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void invoke(LinkedHashMap<String, Object> row, AnalysisContext analysisContext) {
|
|
|
+ public void invoke(LinkedHashMap<Integer, Object> row, AnalysisContext analysisContext) {
|
|
|
ReadSheetHolder sheetHolder = analysisContext.readSheetHolder();
|
|
|
String sheetName = sheetHolder.getSheetName();
|
|
|
if (sheetName.contains("封面") && sheetHolder.getSheetNo() == 0) {
|
|
|
return;
|
|
|
}
|
|
|
@SuppressWarnings("unchecked")
|
|
|
- List<String> tableTitles = (List<String>) analysisContext.getCustom();
|
|
|
- String title = ReportParseUtils.cleaningValue(row.get("1"));
|
|
|
- if (tableTitles.contains(title)) {
|
|
|
- this.table = new SimpleTable(title);
|
|
|
- this.tables.add(table);
|
|
|
+ List<CustomExcelTable> customExcelTables = (List<CustomExcelTable>) analysisContext.getCustom();
|
|
|
+ String title = ReportParseUtils.cleaningValue(row.get(1));
|
|
|
+ if (title != null) {
|
|
|
+ for (CustomExcelTable customExcelTable : customExcelTables) {
|
|
|
+ String tableTitle = customExcelTable.getTitle();
|
|
|
+ if (title.equals(tableTitle) || title.contains(tableTitle)) {
|
|
|
+ this.table = new SimpleTable(tableTitle, customExcelTable.getColCount());
|
|
|
+ this.tables.add(this.table);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
-
|
|
|
- List<String> tableRow = ListUtil.list(true);
|
|
|
- for (int i = 1; i < row.size(); i++) {
|
|
|
- tableRow.add(ReportParseUtils.cleaningValue(row.get(String.valueOf(i))));
|
|
|
+ if (this.table != null) {
|
|
|
+ List<String> tableRow = ListUtil.list(true);
|
|
|
+ int colCount = this.table.getColCount() <= 0 ? row.size() : this.table.getColCount();
|
|
|
+ for (int i = 1; i < colCount; i++) {
|
|
|
+ tableRow.add(ReportParseUtils.cleaningValue(row.get(i)));
|
|
|
+ }
|
|
|
+ this.table.addRow(tableRow);
|
|
|
}
|
|
|
- this.table.addRow(tableRow);
|
|
|
}
|
|
|
|
|
|
@Override
|