Class CellKit

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

public class CellKit extends Object
Excel表格中单元格工具类
Since:
Java 17+
Author:
Kimi Liu
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static org.apache.poi.ss.usermodel.Cell
    getCell(org.apache.poi.ss.usermodel.Row row, int cellIndex)
    获取单元格,如果单元格不存在,返回NullCell
    static org.apache.poi.ss.util.CellRangeAddress
    getCellRangeAddress(org.apache.poi.ss.usermodel.Cell cell)
    获取合并单元格CellRangeAddress,如果不是返回null
    static org.apache.poi.ss.util.CellRangeAddress
    getCellRangeAddress(org.apache.poi.ss.usermodel.Sheet sheet, int x, int y)
    获取合并单元格CellRangeAddress,如果不是返回null
    static org.apache.poi.ss.util.CellRangeAddress
    getCellRangeAddress(org.apache.poi.ss.usermodel.Sheet sheet, String locationRef)
    获取合并单元格CellRangeAddress,如果不是返回null
    static Object
    getCellValue(org.apache.poi.ss.usermodel.Cell cell)
    获取单元格值
    static Object
    getCellValue(org.apache.poi.ss.usermodel.Cell cell, boolean isTrimCellValue)
    获取单元格值
    static Object
    getCellValue(org.apache.poi.ss.usermodel.Cell cell, CellEditor cellEditor)
    获取单元格值
    static Object
    getCellValue(org.apache.poi.ss.usermodel.Cell cell, org.apache.poi.ss.usermodel.CellType cellType, boolean isTrimCellValue)
    获取单元格值
    static Object
    getCellValue(org.apache.poi.ss.usermodel.Cell cell, org.apache.poi.ss.usermodel.CellType cellType, CellEditor cellEditor)
    获取单元格值 如果单元格值为数字格式,则判断其格式中是否有小数部分,无则返回Long类型,否则返回Double类型
    static org.apache.poi.ss.usermodel.Cell
    getMergedRegionCell(org.apache.poi.ss.usermodel.Cell cell)
    获取合并单元格 传入的x,y坐标(列行数)可以是合并单元格范围内的任意一个单元格
    static org.apache.poi.ss.usermodel.Cell
    getMergedRegionCell(org.apache.poi.ss.usermodel.Sheet sheet, int x, int y)
    获取合并单元格 传入的x,y坐标(列行数)可以是合并单元格范围内的任意一个单元格
    static Object
    getMergedRegionValue(org.apache.poi.ss.usermodel.Sheet sheet, int x, int y)
    获取合并单元格的值 传入的x,y坐标(列行数)可以是合并单元格范围内的任意一个单元格
    static Object
    getMergedRegionValue(org.apache.poi.ss.usermodel.Sheet sheet, String locationRef)
    获取合并单元格的值 传入的x,y坐标(列行数)可以是合并单元格范围内的任意一个单元格
    static org.apache.poi.ss.usermodel.Cell
    getOrCreateCell(org.apache.poi.ss.usermodel.Row row, int cellIndex)
    获取已有行或创建新行
    static boolean
    isMergedRegion(org.apache.poi.ss.usermodel.Cell cell)
    判断指定的单元格是否是合并单元格
    static boolean
    isMergedRegion(org.apache.poi.ss.usermodel.Sheet sheet, int x, int y)
    判断指定的单元格是否是合并单元格
    static boolean
    isMergedRegion(org.apache.poi.ss.usermodel.Sheet sheet, String locationRef)
    判断指定的单元格是否是合并单元格
    static int
    mergingCells(org.apache.poi.ss.usermodel.Sheet sheet, int firstRow, int lastRow, int firstColumn, int lastColumn)
    合并单元格,可以根据设置的值来合并行和列
    static int
    mergingCells(org.apache.poi.ss.usermodel.Sheet sheet, int firstRow, int lastRow, int firstColumn, int lastColumn, org.apache.poi.ss.usermodel.CellStyle cellStyle)
    合并单元格,可以根据设置的值来合并行和列
    static void
    setCellValue(org.apache.poi.ss.usermodel.Cell cell, Object value, CellEditor cellEditor)
    设置单元格值 根据传入的styleSet自动匹配样式 当为头部样式时默认赋值头部样式,但是头部中如果有数字、日期等类型,将按照数字、日期样式设置
    static void
    setCellValue(org.apache.poi.ss.usermodel.Cell cell, Object value, StyleSet styleSet, boolean isHeader, CellEditor cellEditor)
    设置单元格值 根据传入的styleSet自动匹配样式 当为头部样式时默认赋值头部样式,但是头部中如果有数字、日期等类型,将按照数字、日期样式设置
    static void
    setCellValue(org.apache.poi.ss.usermodel.Cell cell, Object value, org.apache.poi.ss.usermodel.CellStyle style, CellEditor cellEditor)
    设置单元格值 根据传入的styleSet自动匹配样式 当为头部样式时默认赋值头部样式,但是头部中如果有数字、日期等类型,将按照数字、日期样式设置
    static void
    setComment(org.apache.poi.ss.usermodel.Cell cell, String text, String author, org.apache.poi.ss.usermodel.ClientAnchor anchor)
    为特定单元格添加批注
    static void
    setMergedRegionStyle(org.apache.poi.ss.usermodel.Cell cell, org.apache.poi.ss.usermodel.CellStyle cellStyle)
    设置合并单元格样式,如果不是则不设置

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • CellKit

      public CellKit()
  • Method Details

    • getCellValue

      public static Object getCellValue(org.apache.poi.ss.usermodel.Cell cell)
      获取单元格值
      Parameters:
      cell - Cell单元格
      Returns:
      值,类型可能为:Date、Double、Boolean、String
    • getCellValue

      public static Object getCellValue(org.apache.poi.ss.usermodel.Cell cell, boolean isTrimCellValue)
      获取单元格值
      Parameters:
      cell - Cell单元格
      isTrimCellValue - 如果单元格类型为字符串,是否去掉两边空白符
      Returns:
      值, 类型可能为:Date、Double、Boolean、String
    • getCellValue

      public static Object getCellValue(org.apache.poi.ss.usermodel.Cell cell, CellEditor cellEditor)
      获取单元格值
      Parameters:
      cell - Cell单元格
      cellEditor - 单元格值编辑器 可以通过此编辑器对单元格值做自定义操作
      Returns:
      值, 类型可能为:Date、Double、Boolean、String
    • getCellValue

      public static Object getCellValue(org.apache.poi.ss.usermodel.Cell cell, org.apache.poi.ss.usermodel.CellType cellType, boolean isTrimCellValue)
      获取单元格值
      Parameters:
      cell - Cell单元格
      cellType - 单元格值类型CellType枚举
      isTrimCellValue - 如果单元格类型为字符串,是否去掉两边空白符
      Returns:
      值, 类型可能为:Date、Double、Boolean、String
    • getCellValue

      public static Object getCellValue(org.apache.poi.ss.usermodel.Cell cell, org.apache.poi.ss.usermodel.CellType cellType, CellEditor cellEditor)
      获取单元格值 如果单元格值为数字格式,则判断其格式中是否有小数部分,无则返回Long类型,否则返回Double类型
      Parameters:
      cell - Cell单元格
      cellType - 单元格值类型CellType枚举,如果为null默认使用cell的类型
      cellEditor - 单元格值编辑器 可以通过此编辑器对单元格值做自定义操作
      Returns:
      值, 类型可能为:Date、Double、Boolean、String
    • setCellValue

      public static void setCellValue(org.apache.poi.ss.usermodel.Cell cell, Object value, StyleSet styleSet, boolean isHeader, CellEditor cellEditor)
      设置单元格值 根据传入的styleSet自动匹配样式 当为头部样式时默认赋值头部样式,但是头部中如果有数字、日期等类型,将按照数字、日期样式设置
      Parameters:
      cell - 单元格
      value - 值
      styleSet - 单元格样式集,包括日期等样式,null表示无样式
      isHeader - 是否为标题单元格
      cellEditor - 单元格值编辑器,可修改单元格值或修改单元格,null表示不编辑
    • setCellValue

      public static void setCellValue(org.apache.poi.ss.usermodel.Cell cell, Object value, org.apache.poi.ss.usermodel.CellStyle style, CellEditor cellEditor)
      设置单元格值 根据传入的styleSet自动匹配样式 当为头部样式时默认赋值头部样式,但是头部中如果有数字、日期等类型,将按照数字、日期样式设置
      Parameters:
      cell - 单元格
      value - 值
      style - 自定义样式,null表示无样式
      cellEditor - 单元格值编辑器,可修改单元格值或修改单元格,null表示不编辑
    • setCellValue

      public static void setCellValue(org.apache.poi.ss.usermodel.Cell cell, Object value, CellEditor cellEditor)
      设置单元格值 根据传入的styleSet自动匹配样式 当为头部样式时默认赋值头部样式,但是头部中如果有数字、日期等类型,将按照数字、日期样式设置
      Parameters:
      cell - 单元格
      value - 值或CellSetter
      cellEditor - 单元格值编辑器,可修改单元格值或修改单元格,null表示不编辑
    • setComment

      public static void setComment(org.apache.poi.ss.usermodel.Cell cell, String text, String author, org.apache.poi.ss.usermodel.ClientAnchor anchor)
      为特定单元格添加批注
      Parameters:
      cell - 单元格
      text - 批注内容
      author - 作者
      anchor - 批注的位置、大小等信息,null表示使用默认
    • getCell

      public static org.apache.poi.ss.usermodel.Cell getCell(org.apache.poi.ss.usermodel.Row row, int cellIndex)
      获取单元格,如果单元格不存在,返回NullCell
      Parameters:
      row - Excel表的行
      cellIndex - 列号
      Returns:
      Cell
    • getOrCreateCell

      public static org.apache.poi.ss.usermodel.Cell getOrCreateCell(org.apache.poi.ss.usermodel.Row row, int cellIndex)
      获取已有行或创建新行
      Parameters:
      row - Excel表的行
      cellIndex - 列号
      Returns:
      Cell
    • isMergedRegion

      public static boolean isMergedRegion(org.apache.poi.ss.usermodel.Sheet sheet, String locationRef)
      判断指定的单元格是否是合并单元格
      Parameters:
      sheet - Sheet
      locationRef - 单元格地址标识符,例如A11,B5
      Returns:
      是否是合并单元格
    • isMergedRegion

      public static boolean isMergedRegion(org.apache.poi.ss.usermodel.Cell cell)
      判断指定的单元格是否是合并单元格
      Parameters:
      cell - Cell
      Returns:
      是否是合并单元格
    • isMergedRegion

      public static boolean isMergedRegion(org.apache.poi.ss.usermodel.Sheet sheet, int x, int y)
      判断指定的单元格是否是合并单元格
      Parameters:
      sheet - Sheet
      x - 列号,从0开始
      y - 行号,从0开始
      Returns:
      是否是合并单元格
    • getCellRangeAddress

      public static org.apache.poi.ss.util.CellRangeAddress getCellRangeAddress(org.apache.poi.ss.usermodel.Sheet sheet, String locationRef)
      获取合并单元格CellRangeAddress,如果不是返回null
      Parameters:
      sheet - Sheet
      locationRef - 单元格地址标识符,例如A11,B5
      Returns:
      CellRangeAddress
    • getCellRangeAddress

      public static org.apache.poi.ss.util.CellRangeAddress getCellRangeAddress(org.apache.poi.ss.usermodel.Cell cell)
      获取合并单元格CellRangeAddress,如果不是返回null
      Parameters:
      cell - Cell
      Returns:
      CellRangeAddress
    • getCellRangeAddress

      public static org.apache.poi.ss.util.CellRangeAddress getCellRangeAddress(org.apache.poi.ss.usermodel.Sheet sheet, int x, int y)
      获取合并单元格CellRangeAddress,如果不是返回null
      Parameters:
      sheet - Sheet
      x - 列号,从0开始
      y - 行号,从0开始
      Returns:
      CellRangeAddress
    • setMergedRegionStyle

      public static void setMergedRegionStyle(org.apache.poi.ss.usermodel.Cell cell, org.apache.poi.ss.usermodel.CellStyle cellStyle)
      设置合并单元格样式,如果不是则不设置
      Parameters:
      cell - Cell
      cellStyle - CellStyle
    • mergingCells

      public static int mergingCells(org.apache.poi.ss.usermodel.Sheet sheet, int firstRow, int lastRow, int firstColumn, int lastColumn)
      合并单元格,可以根据设置的值来合并行和列
      Parameters:
      sheet - 表对象
      firstRow - 起始行,0开始
      lastRow - 结束行,0开始
      firstColumn - 起始列,0开始
      lastColumn - 结束列,0开始
      Returns:
      合并后的单元格号
    • mergingCells

      public static int mergingCells(org.apache.poi.ss.usermodel.Sheet sheet, int firstRow, int lastRow, int firstColumn, int lastColumn, org.apache.poi.ss.usermodel.CellStyle cellStyle)
      合并单元格,可以根据设置的值来合并行和列
      Parameters:
      sheet - 表对象
      firstRow - 起始行,0开始
      lastRow - 结束行,0开始
      firstColumn - 起始列,0开始
      lastColumn - 结束列,0开始
      cellStyle - 单元格样式,只提取边框样式,null表示无样式
      Returns:
      合并后的单元格号
    • getMergedRegionValue

      public static Object getMergedRegionValue(org.apache.poi.ss.usermodel.Sheet sheet, String locationRef)
      获取合并单元格的值 传入的x,y坐标(列行数)可以是合并单元格范围内的任意一个单元格
      Parameters:
      sheet - Sheet
      locationRef - 单元格地址标识符,例如A11,B5
      Returns:
      合并单元格的值
    • getMergedRegionValue

      public static Object getMergedRegionValue(org.apache.poi.ss.usermodel.Sheet sheet, int x, int y)
      获取合并单元格的值 传入的x,y坐标(列行数)可以是合并单元格范围内的任意一个单元格
      Parameters:
      sheet - Sheet
      x - 列号,从0开始,可以是合并单元格范围中的任意一列
      y - 行号,从0开始,可以是合并单元格范围中的任意一行
      Returns:
      合并单元格的值
    • getMergedRegionCell

      public static org.apache.poi.ss.usermodel.Cell getMergedRegionCell(org.apache.poi.ss.usermodel.Cell cell)
      获取合并单元格 传入的x,y坐标(列行数)可以是合并单元格范围内的任意一个单元格
      Parameters:
      cell - Cell
      Returns:
      合并单元格
    • getMergedRegionCell

      public static org.apache.poi.ss.usermodel.Cell getMergedRegionCell(org.apache.poi.ss.usermodel.Sheet sheet, int x, int y)
      获取合并单元格 传入的x,y坐标(列行数)可以是合并单元格范围内的任意一个单元格
      Parameters:
      sheet - Sheet
      x - 列号,从0开始,可以是合并单元格范围中的任意一列
      y - 行号,从0开始,可以是合并单元格范围中的任意一行
      Returns:
      合并单元格,如果非合并单元格,返回坐标对应的单元格