Package org.aoju.bus.office.excel
Class StyleKit
java.lang.Object
org.aoju.bus.office.excel.StyleKit
Excel样式工具类
- Since:
- Java 17+
- Author:
- Kimi Liu
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic org.apache.poi.ss.usermodel.CellStylecloneCellStyle(org.apache.poi.ss.usermodel.Cell cell, org.apache.poi.ss.usermodel.CellStyle cellStyle) 克隆新的CellStylestatic org.apache.poi.ss.usermodel.CellStylecloneCellStyle(org.apache.poi.ss.usermodel.Workbook workbook, org.apache.poi.ss.usermodel.CellStyle cellStyle) 克隆新的CellStylestatic org.apache.poi.ss.usermodel.CellStylecreateCellStyle(org.apache.poi.ss.usermodel.Workbook workbook) 创建单元格样式static org.apache.poi.ss.usermodel.CellStylecreateDefaultCellStyle(org.apache.poi.ss.usermodel.Workbook workbook) 创建默认普通单元格样式static org.apache.poi.ss.usermodel.FontcreateFont(org.apache.poi.ss.usermodel.Workbook workbook, short color, short fontSize, String fontName) 创建字体static org.apache.poi.ss.usermodel.CellStylecreateHeadCellStyle(org.apache.poi.ss.usermodel.Workbook workbook) 创建默认头部样式static Short创建数据格式并获取格式static booleanisNullOrDefaultStyle(org.apache.poi.ss.usermodel.Workbook workbook, org.apache.poi.ss.usermodel.CellStyle style) 给定样式是否为null(无样式)或默认样式,默认样式为workbook.getCellStyleAt(0)static org.apache.poi.ss.usermodel.CellStylesetAlign(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.CellStylesetBorder(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.CellStylesetColor(org.apache.poi.ss.usermodel.CellStyle cellStyle, short color, org.apache.poi.ss.usermodel.FillPatternType fillPattern) 给cell设置颜色static org.apache.poi.ss.usermodel.CellStylesetColor(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.FontsetFontStyle(org.apache.poi.ss.usermodel.Font font, short color, short fontSize, String fontName) 设置字体样式
-
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-CellStylehalign- 横向位置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-CellStyleborderSize- 边框粗细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-CellStylecolor- 背景颜色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-CellStylecolor- 背景颜色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-Workbookcolor- 字体颜色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- 字体Fontcolor- 字体颜色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
创建数据格式并获取格式- Parameters:
workbook-Workbookformat- 数据格式- Returns:
- 数据格式
-