|
@@ -7,6 +7,8 @@ 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.io.Closeable;
|
|
|
+import java.io.IOException;
|
|
|
import java.util.LinkedHashMap;
|
|
|
import java.util.List;
|
|
|
|
|
@@ -15,18 +17,16 @@ import java.util.List;
|
|
|
* @date 2024/10/12 9:17
|
|
|
* @description 自定义的excel多sheet解析事件监听器
|
|
|
*/
|
|
|
-public class CustomExcelMultiSheetListener extends AnalysisEventListener<LinkedHashMap<Integer, Object>> {
|
|
|
+public class CustomExcelMultiSheetListener extends AnalysisEventListener<LinkedHashMap<Integer, Object>> implements Closeable {
|
|
|
private final List<SimpleTable> tables = ListUtil.list(false);
|
|
|
private SimpleTable table;
|
|
|
|
|
|
+ private CustomExcelTable customExcelTable;
|
|
|
+
|
|
|
public List<SimpleTable> getTables() {
|
|
|
return tables;
|
|
|
}
|
|
|
|
|
|
- public void cleanTables() {
|
|
|
- this.tables.clear();
|
|
|
- }
|
|
|
-
|
|
|
@Override
|
|
|
public void invoke(LinkedHashMap<Integer, Object> row, AnalysisContext analysisContext) {
|
|
|
ReadSheetHolder sheetHolder = analysisContext.readSheetHolder();
|
|
@@ -39,18 +39,20 @@ public class CustomExcelMultiSheetListener extends AnalysisEventListener<LinkedH
|
|
|
String title = ReportParseUtils.cleaningValue(row.get(1));
|
|
|
if (title != null) {
|
|
|
for (CustomExcelTable customExcelTable : customExcelTables) {
|
|
|
- String tableTitle = customExcelTable.getTitle();
|
|
|
+ String tableTitle = customExcelTable.title();
|
|
|
if (title.equals(tableTitle) || title.contains(tableTitle)) {
|
|
|
- this.table = new SimpleTable(tableTitle, customExcelTable.getColCount());
|
|
|
+ this.table = new SimpleTable(tableTitle, customExcelTable.colCount());
|
|
|
+ this.customExcelTable = customExcelTable;
|
|
|
this.tables.add(this.table);
|
|
|
return;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- if (this.table != null) {
|
|
|
+ int rowCount = this.customExcelTable.rowCount() <= 0 ? Integer.MAX_VALUE : this.customExcelTable.rowCount();
|
|
|
+ if (this.table != null && this.table.getRowCount() < rowCount) {
|
|
|
List<String> tableRow = ListUtil.list(true);
|
|
|
- int colCount = this.table.getColCount() <= 0 ? row.size() : this.table.getColCount();
|
|
|
- for (int i = 1; i < colCount; i++) {
|
|
|
+ int colCount = this.table.getColCount() <= 0 ? row.size() : this.table.getColCount() + this.customExcelTable.startCol();
|
|
|
+ for (int i = this.customExcelTable.startCol(); i < colCount; i++) {
|
|
|
tableRow.add(ReportParseUtils.cleaningValue(row.get(i)));
|
|
|
}
|
|
|
this.table.addRow(tableRow);
|
|
@@ -61,4 +63,9 @@ public class CustomExcelMultiSheetListener extends AnalysisEventListener<LinkedH
|
|
|
public void doAfterAllAnalysed(AnalysisContext analysisContext) {
|
|
|
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void close() throws IOException {
|
|
|
+ this.tables.clear();
|
|
|
+ }
|
|
|
}
|