Package org.miaixz.bus.office.excel.xyz
Class ExcelSaxKit
java.lang.Object
org.miaixz.bus.office.excel.xyz.ExcelSaxKit
Sax方式读取Excel相关工具类
- Author:
- Kimi Liu
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic intcountNullCell(String preRef, String ref) 计算两个单元格之间的单元格数目(同一行)static ExcelSaxReader<?> createSaxReader(boolean isXlsx, RowHandler rowHandler) static StringformatCellContent(String value, int numFmtIndex, String numFmtString) 格式化数字或日期值static ObjectgetDataValue(CellDataType cellDataType, String value, org.apache.poi.xssf.model.SharedStrings sharedStrings, String numFmtString) 根据数据类型获取数据static org.miaixz.bus.core.center.date.DateTimegetDateValue(double value) 获取日期static org.miaixz.bus.core.center.date.DateTimegetDateValue(String value) 获取日期static ObjectgetNumberOrDateValue(org.apache.poi.hssf.record.CellValueRecordInterface cell, double value, org.apache.poi.hssf.eventusermodel.FormatTrackingHSSFListener formatListener) 在Excel03 sax读取中获取日期或数字类型的结果值static booleanisDateFormat(int formatIndex, String formatString) 判断日期格式static booleanisDateFormat(org.apache.poi.hssf.record.CellValueRecordInterface cell, org.apache.poi.hssf.eventusermodel.FormatTrackingHSSFListener formatListener) 判断数字Record中是否为日期格式static voidreadFrom(InputStream xmlDocStream, ContentHandler handler) 从Excel的XML文档中读取内容,并使用ContentHandler处理
-
Constructor Details
-
ExcelSaxKit
public ExcelSaxKit()
-
-
Method Details
-
createSaxReader
- Parameters:
isXlsx- 是否为xlsx格式(07格式)rowHandler- 行处理器- Returns:
ExcelSaxReader
-
formatCellContent
格式化数字或日期值- Parameters:
value- 值numFmtIndex- 数字格式索引numFmtString- 数字格式名- Returns:
- 格式化后的值
-
countNullCell
计算两个单元格之间的单元格数目(同一行)- Parameters:
preRef- 前一个单元格位置,例如A1ref- 当前单元格位置,例如A8- Returns:
- 同一行中两个单元格之间的空单元格数
-
readFrom
public static void readFrom(InputStream xmlDocStream, ContentHandler handler) throws org.miaixz.bus.core.lang.exception.DependencyException, org.miaixz.bus.core.lang.exception.InternalException, org.miaixz.bus.core.lang.exception.RevisedException 从Excel的XML文档中读取内容,并使用ContentHandler处理- Parameters:
xmlDocStream- Excel的XML文档流handler- 文档内容处理接口,实现此接口用于回调处理数据- Throws:
org.miaixz.bus.core.lang.exception.DependencyException- 依赖异常org.miaixz.bus.core.lang.exception.InternalException- POI异常,包装了SAXExceptionorg.miaixz.bus.core.lang.exception.RevisedException- IO异常,如流关闭或异常等
-
isDateFormat
public static boolean isDateFormat(org.apache.poi.hssf.record.CellValueRecordInterface cell, org.apache.poi.hssf.eventusermodel.FormatTrackingHSSFListener formatListener) 判断数字Record中是否为日期格式- Parameters:
cell- 单元格记录formatListener-FormatTrackingHSSFListener- Returns:
- 是否为日期格式
-
isDateFormat
判断日期格式- Parameters:
formatIndex- 格式索引,一般用于内建格式formatString- 格式字符串- Returns:
- 是否为日期格式
- See Also:
-
getDateValue
获取日期- Parameters:
value- 单元格值- Returns:
- 日期
-
getDateValue
public static org.miaixz.bus.core.center.date.DateTime getDateValue(double value) 获取日期- Parameters:
value- 单元格值- Returns:
- 日期
-
getNumberOrDateValue
public static Object getNumberOrDateValue(org.apache.poi.hssf.record.CellValueRecordInterface cell, double value, org.apache.poi.hssf.eventusermodel.FormatTrackingHSSFListener formatListener) 在Excel03 sax读取中获取日期或数字类型的结果值- Parameters:
cell- 记录单元格value- 值formatListener-FormatTrackingHSSFListener- Returns:
- 值,可能为Date或Double或Long
-