Class ExcelSaxKit

java.lang.Object
org.aoju.bus.office.excel.ExcelSaxKit

public class ExcelSaxKit extends Object
Sax方式读取Excel相关工具类
Since:
Java 17+
Author:
Kimi Liu
  • Field Details

  • Constructor Details

    • ExcelSaxKit

      public ExcelSaxKit()
  • Method Details

    • createSaxReader

      public static ExcelSaxReader<?> createSaxReader(boolean isXlsx, RowHandler rowHandler)
      Parameters:
      isXlsx - 是否为xlsx格式(07格式)
      rowHandler - 行处理器
      Returns:
      ExcelSaxReader
    • getDataValue

      public static Object getDataValue(CellDataType cellDataType, String value, org.apache.poi.xssf.model.SharedStrings sharedStrings, String numFmtString)
      根据数据类型获取数据
      Parameters:
      cellDataType - 数据类型枚举
      value - 数据值
      sharedStrings - SharedStrings
      numFmtString - 数字格式名
      Returns:
      数据值
    • formatCellContent

      public static String formatCellContent(String value, int numFmtIndex, String numFmtString)
      格式化数字或日期值
      Parameters:
      value - 值
      numFmtIndex - 数字格式索引
      numFmtString - 数字格式名
      Returns:
      格式化后的值
    • countNullCell

      public static int countNullCell(String preRef, String ref)
      计算两个单元格之间的单元格数目(同一行)
      Parameters:
      preRef - 前一个单元格位置,例如A1
      ref - 当前单元格位置,例如A8
      Returns:
      同一行中两个单元格之间的空单元格数
    • readFrom

      public static void readFrom(InputStream xmlDocStream, ContentHandler handler) throws org.aoju.bus.core.exception.InternalException
      从Excel的XML文档中读取内容,并使用ContentHandler处理
      Parameters:
      xmlDocStream - Excel的XML文档流
      handler - 文档内容处理接口,实现此接口用于回调处理数据
      Throws:
      org.aoju.bus.core.exception.InternalException - POI异常,包装了SAXException
    • getDateValue

      public static org.aoju.bus.core.date.DateTime getDateValue(String value)
      获取日期
      Parameters:
      value - 单元格值
      Returns:
      日期
    • getDateValue

      public static org.aoju.bus.core.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
    • isDateFormat

      public static boolean isDateFormat(org.apache.poi.ss.usermodel.Cell cell)
    • isDateFormat

      public static boolean isDateFormat(org.apache.poi.ss.usermodel.Cell cell, org.apache.poi.ss.formula.ConditionalFormattingEvaluator cfEvaluator)
      判断是否日期格式
      Parameters:
      cell - 单元格
      cfEvaluator - ConditionalFormattingEvaluator
      Returns:
      是否日期格式
    • isDateFormat

      public static boolean isDateFormat(org.apache.poi.ss.usermodel.ExcelNumberFormat numFmt)
      判断是否日期格式
      Parameters:
      numFmt - ExcelNumberFormat
      Returns:
      是否日期格式
    • isDateFormat

      public static boolean isDateFormat(int formatIndex, String formatString)
      判断日期格式
      Parameters:
      formatIndex - 格式索引,一般用于内建格式
      formatString - 格式字符串
      Returns:
      是否为日期格式