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

This commit is contained in:
Looly
2024-12-21 13:09:08 +08:00
parent 35505dfbf8
commit 5dea0ed2b5
5 changed files with 76 additions and 2 deletions

View File

@@ -26,6 +26,7 @@ import org.dromara.hutool.core.text.StrUtil;
import org.dromara.hutool.poi.excel.ExcelUtil;
import org.dromara.hutool.poi.excel.cell.values.FormulaCellValue;
import org.dromara.hutool.poi.excel.sax.Excel03SaxReader;
import org.dromara.hutool.poi.excel.sax.StopReadException;
import org.dromara.hutool.poi.excel.sax.handler.RowHandler;
import org.dromara.hutool.poi.POIException;
import org.apache.poi.ss.usermodel.CellStyle;
@@ -51,6 +52,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() {
// 工具化快速读取