(curCell + 1);
- // 行数增加
- index++;
- // 当前列置0
- curCell = 0;
- // 置空当前列坐标和前一列坐标
- curCoordinate = null;
- preCoordinate = null;
- }
-
- /**
- * 在一行中的指定列增加值
- *
- * @param index 位置
- * @param value 值
- */
- private void addCellValue(int index, Object value) {
- this.rowCellList.add(index, value);
- this.rowHandler.handleCell(this.sheetIndex, this.rowNumber, index, value, this.xssfCellStyle);
- }
-
- /**
- * 填充空白单元格,如果前一个单元格大于后一个,不需要填充
- *
- * @param preCoordinate 前一个单元格坐标
- * @param curCoordinate 当前单元格坐标
- * @param isEnd 是否为最后一个单元格
- */
- private void fillBlankCell(String preCoordinate, String curCoordinate, boolean isEnd) {
- if (false == curCoordinate.equals(preCoordinate)) {
- int len = ExcelSaxUtil.countNullCell(preCoordinate, curCoordinate);
- if (isEnd) {
- len++;
- }
- while (len-- > 0) {
- addCellValue(curCell++, StrUtil.EMPTY);
- }
- }
- }
-
- /**
- * 设置单元格的类型
- *
- * @param attributes 属性
- */
- private void setCellType(Attributes attributes) {
- // numFmtString的值
- numFmtString = StrUtil.EMPTY;
- this.cellDataType = CellDataType.of(AttributeName.t.getValue(attributes));
-
- // 获取单元格的xf索引,对应style.xml中cellXfs的子元素xf
- if (null != this.stylesTable) {
- final String xfIndexStr = AttributeName.s.getValue(attributes);
- if (null != xfIndexStr) {
- this.xssfCellStyle = stylesTable.getStyleAt(Integer.parseInt(xfIndexStr));
- // 单元格存储格式的索引,对应style.xml中的numFmts元素的子元素索引
- final int numFmtIndex = xssfCellStyle.getDataFormat();
- this.numFmtString = ObjectUtil.defaultIfNull(
- xssfCellStyle.getDataFormatString(),
- BuiltinFormats.getBuiltinFormat(numFmtIndex));
- if (CellDataType.NUMBER == this.cellDataType && ExcelSaxUtil.isDateFormat(numFmtIndex, numFmtString)) {
- cellDataType = CellDataType.DATE;
- }
- }
- }
-
- }
// --------------------------------------------------------------------------------------- Private method end
}
\ No newline at end of file
diff --git a/hutool-poi/src/main/java/cn/hutool/poi/excel/sax/SheetDataSaxHandler.java b/hutool-poi/src/main/java/cn/hutool/poi/excel/sax/SheetDataSaxHandler.java
new file mode 100644
index 000000000..b6d63ee7b
--- /dev/null
+++ b/hutool-poi/src/main/java/cn/hutool/poi/excel/sax/SheetDataSaxHandler.java
@@ -0,0 +1,307 @@
+package cn.hutool.poi.excel.sax;
+
+import cn.hutool.core.text.StrBuilder;
+import cn.hutool.core.util.ObjectUtil;
+import cn.hutool.core.util.StrUtil;
+import cn.hutool.poi.excel.cell.FormulaCellValue;
+import cn.hutool.poi.excel.sax.handler.RowHandler;
+import org.apache.poi.ss.usermodel.BuiltinFormats;
+import org.apache.poi.xssf.model.SharedStringsTable;
+import org.apache.poi.xssf.model.StylesTable;
+import org.apache.poi.xssf.usermodel.XSSFCellStyle;
+import org.xml.sax.Attributes;
+import org.xml.sax.helpers.DefaultHandler;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * sheetData标签内容读取处理器
+ *
+ *
+ * <sheetData></sheetData>
+ *
+ * @since 5.5.3
+ */
+public class SheetDataSaxHandler extends DefaultHandler {
+
+ // 单元格的格式表,对应style.xml
+ protected StylesTable stylesTable;
+ // excel 2007 的共享字符串表,对应sharedString.xml
+ protected SharedStringsTable sharedStringsTable;
+ // sheet的索引
+ protected int sheetIndex;
+
+ // 当前非空行
+ protected int index;
+ // 当前列
+ private int curCell;
+ // 单元数据类型
+ private CellDataType cellDataType;
+ // 当前行号,从0开始
+ private long rowNumber;
+ // 当前列坐标, 如A1,B5
+ private String curCoordinate;
+ // 当前节点名称
+ private ElementName curElementName;
+ // 前一个列的坐标
+ private String preCoordinate;
+ // 行的最大列坐标
+ private String maxCellCoordinate;
+ // 单元格样式
+ private XSSFCellStyle xssfCellStyle;
+ // 单元格存储的格式化字符串,nmtFmt的formatCode属性的值
+ private String numFmtString;
+ // 是否处于sheetData标签内,sax只解析此标签内的内容,其它标签忽略
+ private boolean isInSheetData;
+
+ // 上一次的内容
+ private final StrBuilder lastContent = StrUtil.strBuilder();
+ // 上一次的内容
+ private final StrBuilder lastFormula = StrUtil.strBuilder();
+ // 存储每行的列元素
+ private List