-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3721 from alibaba/bugfix20240311
Bugfix20240311
- Loading branch information
Showing
13 changed files
with
219 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
...excel-core/src/main/java/com/alibaba/excel/exception/ExcelAnalysisStopSheetException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package com.alibaba.excel.exception; | ||
|
||
/** | ||
* Throw the exception when you need to stop | ||
* This exception will only stop the parsing of the current sheet. If you want to stop the entire excel parsing, please | ||
* use ExcelAnalysisStopException. | ||
* | ||
* The com.alibaba.excel.read.listener.ReadListener#doAfterAllAnalysed(com.alibaba.excel.context.AnalysisContext) method | ||
* is called after the call is stopped. | ||
* | ||
* @author Jiaju Zhuang | ||
* @see ExcelAnalysisStopException | ||
* @since 3.3.4 | ||
*/ | ||
public class ExcelAnalysisStopSheetException extends ExcelAnalysisException { | ||
|
||
public ExcelAnalysisStopSheetException() {} | ||
|
||
public ExcelAnalysisStopSheetException(String message) { | ||
super(message); | ||
} | ||
|
||
public ExcelAnalysisStopSheetException(String message, Throwable cause) { | ||
super(message, cause); | ||
} | ||
|
||
public ExcelAnalysisStopSheetException(Throwable cause) { | ||
super(cause); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
...om/alibaba/easyexcel/test/core/exception/ExcelAnalysisStopSheetExceptionDataListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package com.alibaba.easyexcel.test.core.exception; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashSet; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Set; | ||
|
||
import com.alibaba.excel.context.AnalysisContext; | ||
import com.alibaba.excel.event.AnalysisEventListener; | ||
import com.alibaba.excel.exception.ExcelAnalysisStopException; | ||
import com.alibaba.excel.exception.ExcelAnalysisStopSheetException; | ||
import com.alibaba.excel.util.ListUtils; | ||
import com.alibaba.excel.util.MapUtils; | ||
import com.alibaba.fastjson2.JSON; | ||
|
||
import lombok.Getter; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.apache.commons.collections4.CollectionUtils; | ||
import org.apache.commons.collections4.SetUtils; | ||
import org.assertj.core.internal.Maps; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
/** | ||
* @author Jiaju Zhuang | ||
*/ | ||
@Getter | ||
@Slf4j | ||
public class ExcelAnalysisStopSheetExceptionDataListener extends AnalysisEventListener<ExceptionData> { | ||
|
||
private Map<Integer, List<String>> dataMap = MapUtils.newHashMap(); | ||
|
||
|
||
@Override | ||
public void invoke(ExceptionData data, AnalysisContext context) { | ||
List<String> sheetDataList = dataMap.computeIfAbsent(context.readSheetHolder().getSheetNo(), | ||
key -> ListUtils.newArrayList()); | ||
sheetDataList.add(data.getName()); | ||
if (sheetDataList.size() >= 5) { | ||
throw new ExcelAnalysisStopSheetException(); | ||
} | ||
} | ||
|
||
@Override | ||
public void doAfterAllAnalysed(AnalysisContext context) { | ||
List<String> sheetDataList = dataMap.get(context.readSheetHolder().getSheetNo()); | ||
Assertions.assertNotNull(sheetDataList); | ||
Assertions.assertEquals(5, sheetDataList.size()); | ||
} | ||
} |
Oops, something went wrong.