Class ExcelKit

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

public class ExcelKit extends Object
Excel工具类
Since:
Java 17+
Author:
Kimi Liu
  • Constructor Details

    • ExcelKit

      public ExcelKit()
  • Method Details

    • readBySax

      public static void readBySax(String path, int rid, RowHandler rowHandler)
      通过Sax方式读取Excel,同时支持03和07格式
      Parameters:
      path - Excel文件路径
      rid - sheet rid,-1表示全部Sheet, 0表示第一个Sheet
      rowHandler - 行处理器
    • readBySax

      public static void readBySax(String path, String idOrRid, RowHandler rowHandler)
      通过Sax方式读取Excel,同时支持03和07格式
      Parameters:
      path - Excel文件路径
      idOrRid - Excel中的sheet id或者rid编号,rid必须加rId前缀,例如rId1,如果为-1处理所有编号的sheet
      rowHandler - 行处理器
    • readBySax

      public static void readBySax(File file, int rid, RowHandler rowHandler)
      通过Sax方式读取Excel,同时支持03和07格式
      Parameters:
      file - Excel文件
      rid - sheet rid,-1表示全部Sheet, 0表示第一个Sheet
      rowHandler - 行处理器
    • readBySax

      public static void readBySax(File file, String idOrRid, RowHandler rowHandler)
      通过Sax方式读取Excel,同时支持03和07格式
      Parameters:
      file - Excel文件
      idOrRid - Excel中的sheet id或者rid编号,rid必须加rId前缀,例如rId1,如果为-1处理所有编号的sheet
      rowHandler - 行处理器
    • readBySax

      public static void readBySax(InputStream in, int rid, RowHandler rowHandler)
      通过Sax方式读取Excel,同时支持03和07格式
      Parameters:
      in - Excel流
      rid - sheet rid,-1表示全部Sheet, 0表示第一个Sheet
      rowHandler - 行处理器
    • readBySax

      public static void readBySax(InputStream in, String idOrRid, RowHandler rowHandler)
      通过Sax方式读取Excel,同时支持03和07格式
      Parameters:
      in - Excel流
      idOrRid - Excel中的sheet id或者rid编号,rid必须加rId前缀,例如rId1,如果为-1处理所有编号的sheet
      rowHandler - 行处理器
    • getReader

      public static ExcelReader getReader(String bookFilePath)
      获取Excel读取器,通过调用ExcelReader的read或readXXX方法读取Excel内容 默认调用第一个sheet
      Parameters:
      bookFilePath - Excel文件路径,绝对路径或相对于ClassPath路径
      Returns:
      ExcelReader
    • getReader

      public static ExcelReader getReader(File bookFile)
      获取Excel读取器,通过调用ExcelReader的read或readXXX方法读取Excel内容 默认调用第一个sheet
      Parameters:
      bookFile - Excel文件
      Returns:
      ExcelReader
    • getReader

      public static ExcelReader getReader(String bookFilePath, int sheetIndex)
      获取Excel读取器,通过调用ExcelReader的read或readXXX方法读取Excel内容
      Parameters:
      bookFilePath - Excel文件路径,绝对路径或相对于ClassPath路径
      sheetIndex - sheet序号,0表示第一个sheet
      Returns:
      ExcelReader
    • getReader

      public static ExcelReader getReader(File bookFile, int sheetIndex)
      获取Excel读取器,通过调用ExcelReader的read或readXXX方法读取Excel内容
      Parameters:
      bookFile - Excel文件
      sheetIndex - sheet序号,0表示第一个sheet
      Returns:
      ExcelReader
    • getReader

      public static ExcelReader getReader(File bookFile, String sheetName)
      获取Excel读取器,通过调用ExcelReader的read或readXXX方法读取Excel内容
      Parameters:
      bookFile - Excel文件
      sheetName - sheet名,第一个默认是sheet1
      Returns:
      ExcelReader
    • getReader

      public static ExcelReader getReader(InputStream bookStream)
      获取Excel读取器,通过调用ExcelReader的read或readXXX方法读取Excel内容 默认调用第一个sheet,读取结束自动关闭流
      Parameters:
      bookStream - Excel文件的流
      Returns:
      ExcelReader
    • getReader

      public static ExcelReader getReader(InputStream bookStream, int sheetIndex)
      获取Excel读取器,通过调用ExcelReader的read或readXXX方法读取Excel内容 读取结束自动关闭流
      Parameters:
      bookStream - Excel文件的流
      sheetIndex - sheet序号,0表示第一个sheet
      Returns:
      ExcelReader
    • getReader

      public static ExcelReader getReader(InputStream bookStream, String sheetName)
      获取Excel读取器,通过调用ExcelReader的read或readXXX方法读取Excel内容 读取结束自动关闭流
      Parameters:
      bookStream - Excel文件的流
      sheetName - sheet名,第一个默认是sheet1
      Returns:
      ExcelReader
    • getReader

      public static ExcelReader getReader(String bookFilePath, String sheetName)
      获取Excel读取器,通过调用ExcelReader的read或readXXX方法读取Excel内容
      Parameters:
      bookFilePath - Excel文件路径,绝对路径或相对于ClassPath路径
      sheetName - sheet名,第一个默认是sheet1
      Returns:
      ExcelReader
    • getWriter

      public static ExcelWriter getWriter()
      获得ExcelWriter,默认写出到第一个sheet 不传入写出的Excel文件路径,只能调用ExcelWriter.flush(OutputStream)方法写出到流 若写出到文件,还需调用ExcelWriter.setDestFile(File)方法自定义写出的文件,然后调用ExcelWriter.flush()方法写出到文件
      Returns:
      ExcelWriter
    • getWriter

      public static ExcelWriter getWriter(boolean isXlsx)
      获得ExcelWriter,默认写出到第一个sheet 不传入写出的Excel文件路径,只能调用ExcelWriter.flush(OutputStream)方法写出到流 若写出到文件,还需调用ExcelWriter.setDestFile(File)方法自定义写出的文件,然后调用ExcelWriter.flush()方法写出到文件
      Parameters:
      isXlsx - 是否为xlsx格式
      Returns:
      ExcelWriter
    • getWriter

      public static ExcelWriter getWriter(String destFilePath)
      获得ExcelWriter,默认写出到第一个sheet
      Parameters:
      destFilePath - 目标文件路径
      Returns:
      ExcelWriter
    • getWriter

      public static ExcelWriter getWriter(File destFile)
      获得ExcelWriter,默认写出到第一个sheet,名字为sheet1
      Parameters:
      destFile - 目标文件
      Returns:
      ExcelWriter
    • getWriter

      public static ExcelWriter getWriter(String destFilePath, String sheetName)
      Parameters:
      destFilePath - 目标文件路径
      sheetName - sheet表名
      Returns:
      ExcelWriter
    • getWriter

      public static ExcelWriter getWriter(File destFile, String sheetName)
      Parameters:
      destFile - 目标文件
      sheetName - sheet表名
      Returns:
      ExcelWriter
    • getBigWriter

      public static BigExcelWriter getBigWriter()
      获得BigExcelWriter,默认写出到第一个sheet 不传入写出的Excel文件路径,只能调用ExcelWriter.flush(OutputStream)方法写出到流 若写出到文件,还需调用ExcelWriter.setDestFile(File)方法自定义写出的文件,然后调用ExcelWriter.flush()方法写出到文件
      Returns:
      BigExcelWriter
    • getBigWriter

      public static BigExcelWriter getBigWriter(int rowAccessWindowSize)
      获得BigExcelWriter,默认写出到第一个sheet 不传入写出的Excel文件路径,只能调用ExcelWriter.flush(OutputStream)方法写出到流 若写出到文件,还需调用ExcelWriter.setDestFile(File)方法自定义写出的文件,然后调用ExcelWriter.flush()方法写出到文件
      Parameters:
      rowAccessWindowSize - 在内存中的行数
      Returns:
      BigExcelWriter
    • getBigWriter

      public static BigExcelWriter getBigWriter(String destFilePath)
      获得BigExcelWriter,默认写出到第一个sheet
      Parameters:
      destFilePath - 目标文件路径
      Returns:
      BigExcelWriter
    • getBigWriter

      public static BigExcelWriter getBigWriter(File destFile)
      获得BigExcelWriter,默认写出到第一个sheet,名字为sheet1
      Parameters:
      destFile - 目标文件
      Returns:
      BigExcelWriter
    • getBigWriter

      public static BigExcelWriter getBigWriter(String destFilePath, String sheetName)
      Parameters:
      destFilePath - 目标文件路径
      sheetName - sheet表名
      Returns:
      BigExcelWriter
    • getBigWriter

      public static BigExcelWriter getBigWriter(File destFile, String sheetName)
      Parameters:
      destFile - 目标文件
      sheetName - sheet表名
      Returns:
      BigExcelWriter
    • indexToColName

      public static String indexToColName(int index)
      将Sheet列号变为列名
      Parameters:
      index - 列号, 从0开始
      Returns:
      the sring
    • colNameToIndex

      public static int colNameToIndex(String colName)
      根据表元的列名转换为列号
      Parameters:
      colName - 列名, 从A开始
      Returns:
      the int
    • toLocation

      public static CellLocation toLocation(String locationRef)
      将Excel中地址标识符(例如A11,B5)等转换为行列表示 例如:A11 - x:0,y:10,B5 - x:1,y:4
      Parameters:
      locationRef - 单元格地址标识符,例如A11,B5
      Returns:
      坐标点,x表示行,从0开始,y表示列,从0开始