添加StopReadException,定义sax读取时用户可手动终止(issue#3820@Github)

This commit is contained in:
Looly
2024-12-21 13:09:03 +08:00
parent c45232e235
commit fe74f26f6f
5 changed files with 60 additions and 3 deletions

View File

@@ -8,6 +8,7 @@ import cn.hutool.core.lang.Console;
import cn.hutool.core.util.StrUtil;
import cn.hutool.poi.excel.cell.FormulaCellValue;
import cn.hutool.poi.excel.sax.Excel03SaxReader;
import cn.hutool.poi.excel.sax.StopReadException;
import cn.hutool.poi.excel.sax.handler.RowHandler;
import cn.hutool.poi.exceptions.POIException;
import org.apache.poi.ss.usermodel.CellStyle;
@@ -33,6 +34,24 @@ public class ExcelSaxReadTest {
ExcelUtil.readBySax("aaa.xlsx", 0, createRowHandler());
}
@Test
void readEndByExceptionTest(){
ExcelUtil.readBySax("aaa.xlsx", 0, (sheetIndex, rowIndex, rowList) -> {
if (rowIndex == 1) {
throw new StopReadException();
}
});
}
@Test
void readEndByException03Test(){
ExcelUtil.readBySax("aaa.xls", 0, (sheetIndex, rowIndex, rowList) -> {
if (rowIndex == 1) {
throw new StopReadException();
}
});
}
@Test
public void excel07ByNameTest() {
// 工具化快速读取