Class StyleKit

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

public class StyleKit 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.CellStyle
    cloneCellStyle(org.apache.poi.ss.usermodel.Cell cell, org.apache.poi.ss.usermodel.CellStyle cellStyle)
    克隆新的CellStyle
    static org.apache.poi.ss.usermodel.CellStyle
    cloneCellStyle(org.apache.poi.ss.usermodel.Workbook workbook, org.apache.poi.ss.usermodel.CellStyle cellStyle)
    克隆新的CellStyle
    static org.apache.poi.ss.usermodel.CellStyle
    createCellStyle(org.apache.poi.ss.usermodel.Workbook workbook)
    创建单元格样式
    static org.apache.poi.ss.usermodel.CellStyle
    createDefaultCellStyle(org.apache.poi.ss.usermodel.Workbook workbook)
    创建默认普通单元格样式
    static org.apache.poi.ss.usermodel.Font
    createFont(org.apache.poi.ss.usermodel.Workbook workbook, short color, short fontSize, String fontName)
    创建字体
    static org.apache.poi.ss.usermodel.CellStyle
    createHeadCellStyle(org.apache.poi.ss.usermodel.Workbook workbook)
    创建默认头部样式
    static Short
    getFormat(org.apache.poi.ss.usermodel.Workbook workbook, String format)
    创建数据格式并获取格式
    static boolean
    isNullOrDefaultStyle(org.apache.poi.ss.usermodel.Workbook workbook, org.apache.poi.ss.usermodel.CellStyle style)
    给定样式是否为null(无样式)或默认样式,默认样式为workbook.getCellStyleAt(0)
    static org.apache.poi.ss.usermodel.CellStyle
    setAlign(org.apache.poi.ss.usermodel.CellStyle cellStyle, org.apache.poi.ss.usermodel.HorizontalAlignment halign, org.apache.poi.ss.usermodel.VerticalAlignment valign)
    设置cell文本对齐样式
    static org.apache.poi.ss.usermodel.CellStyle
    setBorder(org.apache.poi.ss.usermodel.CellStyle cellStyle, org.apache.poi.ss.usermodel.BorderStyle borderSize, org.apache.poi.ss.usermodel.IndexedColors colorIndex)
    设置cell的四个边框粗细和颜色
    static org.apache.poi.ss.usermodel.CellStyle
    setColor(org.apache.poi.ss.usermodel.CellStyle cellStyle, short color, org.apache.poi.ss.usermodel.FillPatternType fillPattern)
    给cell设置颜色
    static org.apache.poi.ss.usermodel.CellStyle
    setColor(org.apache.poi.ss.usermodel.CellStyle cellStyle, org.apache.poi.ss.usermodel.IndexedColors color, org.apache.poi.ss.usermodel.FillPatternType fillPattern)
    给cell设置颜色
    static org.apache.poi.ss.usermodel.Font
    setFontStyle(org.apache.poi.ss.usermodel.Font font, short color, short fontSize, String fontName)
    设置字体样式

    Methods inherited from class java.lang.Object

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

    • StyleKit

      public StyleKit()
  • Method Details

    • cloneCellStyle

      public static org.apache.poi.ss.usermodel.CellStyle cloneCellStyle(org.apache.poi.ss.usermodel.Cell cell, org.apache.poi.ss.usermodel.CellStyle cellStyle)
      克隆新的CellStyle
      Parameters:
      cell - 单元格
      cellStyle - 被复制的样式
      Returns:
      CellStyle
    • cloneCellStyle

      public static org.apache.poi.ss.usermodel.CellStyle cloneCellStyle(org.apache.poi.ss.usermodel.Workbook workbook, org.apache.poi.ss.usermodel.CellStyle cellStyle)
      克隆新的CellStyle
      Parameters:
      workbook - 工作簿
      cellStyle - 被复制的样式
      Returns:
      CellStyle
    • setAlign

      public static org.apache.poi.ss.usermodel.CellStyle setAlign(org.apache.poi.ss.usermodel.CellStyle cellStyle, org.apache.poi.ss.usermodel.HorizontalAlignment halign, org.apache.poi.ss.usermodel.VerticalAlignment valign)
      设置cell文本对齐样式
      Parameters:
      cellStyle - CellStyle
      halign - 横向位置
      valign - 纵向位置
      Returns:
      CellStyle
    • setBorder

      public static org.apache.poi.ss.usermodel.CellStyle setBorder(org.apache.poi.ss.usermodel.CellStyle cellStyle, org.apache.poi.ss.usermodel.BorderStyle borderSize, org.apache.poi.ss.usermodel.IndexedColors colorIndex)
      设置cell的四个边框粗细和颜色
      Parameters:
      cellStyle - CellStyle
      borderSize - 边框粗细BorderStyle枚举
      colorIndex - 颜色的short值
      Returns:
      CellStyle
    • setColor

      public static org.apache.poi.ss.usermodel.CellStyle setColor(org.apache.poi.ss.usermodel.CellStyle cellStyle, org.apache.poi.ss.usermodel.IndexedColors color, org.apache.poi.ss.usermodel.FillPatternType fillPattern)
      给cell设置颜色
      Parameters:
      cellStyle - CellStyle
      color - 背景颜色
      fillPattern - 填充方式 FillPatternType枚举
      Returns:
      CellStyle
    • setColor

      public static org.apache.poi.ss.usermodel.CellStyle setColor(org.apache.poi.ss.usermodel.CellStyle cellStyle, short color, org.apache.poi.ss.usermodel.FillPatternType fillPattern)
      给cell设置颜色
      Parameters:
      cellStyle - CellStyle
      color - 背景颜色
      fillPattern - 填充方式 FillPatternType枚举
      Returns:
      CellStyle
    • createFont

      public static org.apache.poi.ss.usermodel.Font createFont(org.apache.poi.ss.usermodel.Workbook workbook, short color, short fontSize, String fontName)
      创建字体
      Parameters:
      workbook - Workbook
      color - 字体颜色
      fontSize - 字体大小
      fontName - 字体名称,可以为null使用默认字体
      Returns:
      Font
    • setFontStyle

      public static org.apache.poi.ss.usermodel.Font setFontStyle(org.apache.poi.ss.usermodel.Font font, short color, short fontSize, String fontName)
      设置字体样式
      Parameters:
      font - 字体Font
      color - 字体颜色
      fontSize - 字体大小
      fontName - 字体名称,可以为null使用默认字体
      Returns:
      Font
    • createCellStyle

      public static org.apache.poi.ss.usermodel.CellStyle createCellStyle(org.apache.poi.ss.usermodel.Workbook workbook)
      创建单元格样式
      Parameters:
      workbook - Workbook 工作簿
      Returns:
      CellStyle
      See Also:
      • Workbook.createCellStyle()
    • createDefaultCellStyle

      public static org.apache.poi.ss.usermodel.CellStyle createDefaultCellStyle(org.apache.poi.ss.usermodel.Workbook workbook)
      创建默认普通单元格样式
       1. 文字上下左右居中
       2. 细边框,黑色
       
      Parameters:
      workbook - Workbook 工作簿
      Returns:
      CellStyle
    • createHeadCellStyle

      public static org.apache.poi.ss.usermodel.CellStyle createHeadCellStyle(org.apache.poi.ss.usermodel.Workbook workbook)
      创建默认头部样式
      Parameters:
      workbook - Workbook 工作簿
      Returns:
      CellStyle
    • isNullOrDefaultStyle

      public static boolean isNullOrDefaultStyle(org.apache.poi.ss.usermodel.Workbook workbook, org.apache.poi.ss.usermodel.CellStyle style)
      给定样式是否为null(无样式)或默认样式,默认样式为workbook.getCellStyleAt(0)
      Parameters:
      workbook - 工作簿
      style - 被检查的样式
      Returns:
      是否为null(无样式)或默认样式
    • getFormat

      public static Short getFormat(org.apache.poi.ss.usermodel.Workbook workbook, String format)
      创建数据格式并获取格式
      Parameters:
      workbook - Workbook
      format - 数据格式
      Returns:
      数据格式