public class StyleUtil extends Object
| Constructor and Description |
|---|
StyleUtil() |
| Modifier and Type | Method and 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)
创建默认普通单元格样式
1.
|
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 |
setBorder(org.apache.poi.ss.usermodel.CellStyle cellStyle,
CellBorderStyle cellBorderStyle)
设置cell的四个边框粗细和颜色
|
static void |
setBorderStyle(org.apache.poi.ss.usermodel.Sheet sheet,
org.apache.poi.ss.util.CellRangeAddress cellRangeAddress,
CellBorderStyle cellBorderStyle)
根据
CellStyle设置指定范围边框样式 |
static void |
setBorderStyle(org.apache.poi.ss.usermodel.Sheet sheet,
org.apache.poi.ss.util.CellRangeAddress cellRangeAddress,
org.apache.poi.ss.usermodel.CellStyle cellStyle)
根据
CellStyle设置指定范围边框样式 |
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.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.xssf.usermodel.XSSFCellStyle cellStyle,
org.apache.poi.xssf.usermodel.XSSFColor 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)
设置字体样式
|
public static org.apache.poi.ss.usermodel.CellStyle createCellStyle(org.apache.poi.ss.usermodel.Workbook workbook)
workbook - Workbook 工作簿CellStyleWorkbook.createCellStyle()public static org.apache.poi.ss.usermodel.CellStyle createDefaultCellStyle(org.apache.poi.ss.usermodel.Workbook workbook)
1. 文字上下左右居中 2. 细边框,黑色
workbook - Workbook 工作簿CellStylepublic static org.apache.poi.ss.usermodel.CellStyle createHeadCellStyle(org.apache.poi.ss.usermodel.Workbook workbook)
workbook - Workbook 工作簿CellStylepublic static boolean isNullOrDefaultStyle(org.apache.poi.ss.usermodel.Workbook workbook,
org.apache.poi.ss.usermodel.CellStyle style)
workbook.getCellStyleAt(0)workbook - 工作簿style - 被检查的样式public static org.apache.poi.ss.usermodel.CellStyle cloneCellStyle(org.apache.poi.ss.usermodel.Cell cell,
org.apache.poi.ss.usermodel.CellStyle cellStyle)
CellStylecell - 单元格cellStyle - 被复制的样式CellStylepublic static org.apache.poi.ss.usermodel.CellStyle cloneCellStyle(org.apache.poi.ss.usermodel.Workbook workbook,
org.apache.poi.ss.usermodel.CellStyle cellStyle)
CellStyleworkbook - 工作簿cellStyle - 被复制的样式CellStylepublic 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)
cellStyle - CellStylehalign - 横向位置valign - 纵向位置CellStylepublic 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)
cellStyle - CellStyleborderSize - 边框粗细BorderStyle枚举colorIndex - 预定义颜色的short值,见IndexedColors枚举CellStylepublic static org.apache.poi.ss.usermodel.CellStyle setBorder(org.apache.poi.ss.usermodel.CellStyle cellStyle,
CellBorderStyle cellBorderStyle)
cellStyle - CellStylecellBorderStyle - CellBorderStyle单元格边框样式和颜色
}CellStylepublic static void setBorderStyle(org.apache.poi.ss.usermodel.Sheet sheet,
org.apache.poi.ss.util.CellRangeAddress cellRangeAddress,
CellBorderStyle cellBorderStyle)
CellStyle设置指定范围边框样式sheet - SheetcellRangeAddress - 边框样式范围cellBorderStyle - 边框风格,包括边框样式、颜色public static void setBorderStyle(org.apache.poi.ss.usermodel.Sheet sheet,
org.apache.poi.ss.util.CellRangeAddress cellRangeAddress,
org.apache.poi.ss.usermodel.CellStyle cellStyle)
CellStyle设置指定范围边框样式sheet - SheetcellRangeAddress - CellRangeAddresscellStyle - CellStylepublic 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)
cellStyle - CellStylecolor - 预定义的背景颜色,见IndexedColors枚举fillPattern - 填充方式 FillPatternType枚举CellStylepublic static org.apache.poi.ss.usermodel.CellStyle setColor(org.apache.poi.ss.usermodel.CellStyle cellStyle,
short color,
org.apache.poi.ss.usermodel.FillPatternType fillPattern)
cellStyle - CellStylecolor - 预定义的背景颜色,见IndexedColors枚举fillPattern - 填充方式 FillPatternType枚举CellStylepublic static org.apache.poi.ss.usermodel.CellStyle setColor(org.apache.poi.xssf.usermodel.XSSFCellStyle cellStyle,
org.apache.poi.xssf.usermodel.XSSFColor color,
org.apache.poi.ss.usermodel.FillPatternType fillPattern)
cellStyle - CellStylecolor - 背景颜色fillPattern - 填充方式 FillPatternType枚举CellStylepublic static org.apache.poi.ss.usermodel.Font createFont(org.apache.poi.ss.usermodel.Workbook workbook,
short color,
short fontSize,
String fontName)
workbook - Workbookcolor - 字体颜色fontSize - 字体大小fontName - 字体名称,可以为null使用默认字体Fontpublic static org.apache.poi.ss.usermodel.Font setFontStyle(org.apache.poi.ss.usermodel.Font font,
short color,
short fontSize,
String fontName)
font - 字体Fontcolor - 字体颜色fontSize - 字体大小fontName - 字体名称,可以为null使用默认字体FontCopyright © 2025. All rights reserved.