- * <sheetData></sheetData> - *+ *
{@code
+ *
+ * }
*
* @since 5.5.3
*/
@@ -60,7 +60,7 @@ public class SheetDataSaxHandler extends DefaultHandler {
/**
* sheet索引,从0开始
*/
- protected int sheetIndex;
+ protected int rid;
/**
* 当前非空行索引,从0开始
*/
@@ -274,7 +274,7 @@ public class SheetDataSaxHandler extends DefaultHandler {
padCell(curCoordinate, maxCellCoordinate, true);
}
- rowHandler.handle(sheetIndex, rowNumber, rowCellList);
+ rowHandler.handle(rid, rowNumber, rowCellList);
// 一行结束
// 新建一个新列,之前的列抛弃(可能被回收或rowHandler处理)
@@ -319,7 +319,7 @@ public class SheetDataSaxHandler extends DefaultHandler {
*/
private void addCellValue(final int index, final Object value) {
this.rowCellList.add(index, value);
- this.rowHandler.handleCell(this.sheetIndex, this.rowNumber, index, value, this.xssfCellStyle);
+ this.rowHandler.handleCell(this.rid, this.rowNumber, index, value, this.xssfCellStyle);
}
/**
diff --git a/hutool-poi/src/main/java/cn/hutool/v7/poi/excel/sax/SheetRidReader.java b/hutool-poi/src/main/java/cn/hutool/v7/poi/excel/sax/SheetRidReader.java
index 95e4a31c88..4969da2aec 100644
--- a/hutool-poi/src/main/java/cn/hutool/v7/poi/excel/sax/SheetRidReader.java
+++ b/hutool-poi/src/main/java/cn/hutool/v7/poi/excel/sax/SheetRidReader.java
@@ -35,9 +35,9 @@ import java.util.Map;
/**
* 在Sax方式读取Excel时,读取sheet标签中sheetId和rid的对应关系,类似于:
- * - * <sheet name="Sheet6" sheetId="4" r:id="rId6"/> - *+ *
{@code
+ *
+ * }
* * 读取结果为: * @@ -100,21 +100,6 @@ public class SheetRidReader extends DefaultHandler { return ID_RID_MAP.get(sheetId); } - /** - * 根据sheetId获取rid,从0开始 - * - * @param sheetId Sheet的ID,从0开始 - * @return rid,从0开始 - * @since 5.5.5 - */ - public Integer getRidBySheetIdBase0(final int sheetId) { - final Integer rid = getRidBySheetId(sheetId + 1); - if (null != rid) { - return rid - 1; - } - return null; - } - /** * 根据sheet name获取rid,从1开始 * @@ -125,21 +110,6 @@ public class SheetRidReader extends DefaultHandler { return NAME_RID_MAP.get(sheetName); } - /** - * 根据sheet name获取rid,从0开始 - * - * @param sheetName Sheet的name - * @return rid,从0开始 - * @since 5.5.5 - */ - public Integer getRidByNameBase0(final String sheetName) { - final Integer rid = getRidByName(sheetName); - if (null != rid) { - return rid - 1; - } - return null; - } - /** * 通过sheet的序号获取rid * diff --git a/hutool-poi/src/test/java/cn/hutool/v7/poi/excel/reader/ExcelSaxReadTest.java b/hutool-poi/src/test/java/cn/hutool/v7/poi/excel/reader/ExcelSaxReadTest.java index 2943677050..7509de9259 100644 --- a/hutool-poi/src/test/java/cn/hutool/v7/poi/excel/reader/ExcelSaxReadTest.java +++ b/hutool-poi/src/test/java/cn/hutool/v7/poi/excel/reader/ExcelSaxReadTest.java @@ -39,6 +39,8 @@ import java.util.ArrayList; import java.util.List; import java.util.concurrent.atomic.AtomicInteger; +import static org.junit.jupiter.api.Assertions.assertEquals; + /** * Excel sax方式读取 * @@ -49,12 +51,12 @@ public class ExcelSaxReadTest { @Test public void excel07Test() { // 工具化快速读取 - ExcelUtil.readBySax("aaa.xlsx", 0, createRowHandler()); + ExcelUtil.readBySax("aaa.xlsx", 1, createRowHandler()); } @Test void readEndByExceptionTest(){ - ExcelUtil.readBySax("aaa.xlsx", 0, (sheetIndex, rowIndex, rowList) -> { + ExcelUtil.readBySax("aaa.xlsx", 1, (sheetIndex, rowIndex, rowList) -> { if (rowIndex == 1) { throw new StopReadException(); } @@ -84,7 +86,7 @@ public class ExcelSaxReadTest { @Test public void excel07FromStreamTest() { // issue#1225 非markSupport的流读取会错误 - ExcelUtil.readBySax(IoUtil.toStream(FileUtil.file("aaa.xlsx")), 0, createRowHandler()); + ExcelUtil.readBySax(IoUtil.toStream(FileUtil.file("aaa.xlsx")), 1, createRowHandler()); } @Test @@ -125,12 +127,12 @@ public class ExcelSaxReadTest { @Test public void readBySaxTest() { - ExcelUtil.readBySax("blankAndDateTest.xlsx", "0", createRowHandler()); + ExcelUtil.readBySax("blankAndDateTest.xlsx", "1", createRowHandler()); } @Test public void readBySaxByRidTest() { - ExcelUtil.readBySax("blankAndDateTest.xlsx", 0, createRowHandler()); + ExcelUtil.readBySax("blankAndDateTest.xlsx", 1, createRowHandler()); } @Test @@ -198,7 +200,7 @@ public class ExcelSaxReadTest { rows.add(""); } }); - Assertions.assertEquals(50L, rows.get(3)); + assertEquals(50L, rows.get(3)); } @Test @@ -206,14 +208,14 @@ public class ExcelSaxReadTest { // since 6.0.0修改 // 默认不在行尾对齐单元格,因此只读取了有第二个值的行 final List