public final class CellUtil
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
ALIGNMENT |
static java.lang.String |
BORDER_BOTTOM |
static java.lang.String |
BORDER_LEFT |
static java.lang.String |
BORDER_RIGHT |
static java.lang.String |
BORDER_TOP |
static java.lang.String |
BOTTOM_BORDER_COLOR |
static java.lang.String |
DATA_FORMAT |
static java.lang.String |
FILL_BACKGROUND_COLOR |
static java.lang.String |
FILL_FOREGROUND_COLOR |
static java.lang.String |
FILL_PATTERN |
static java.lang.String |
FONT |
static java.lang.String |
HIDDEN |
static java.lang.String |
INDENTION |
static java.lang.String |
LEFT_BORDER_COLOR |
static java.lang.String |
LOCKED |
static java.lang.String |
RIGHT_BORDER_COLOR |
static java.lang.String |
ROTATION |
static java.lang.String |
TOP_BORDER_COLOR |
static java.lang.String |
VERTICAL_ALIGNMENT |
static java.lang.String |
WRAP_TEXT |
Modifier and Type | Method and Description |
---|---|
static Cell |
createCell(Row row, int column, java.lang.String value)
Create a cell, and give it a value.
(创建一个单元格,并给它一个值。)
|
static Cell |
createCell(Row row, int column, java.lang.String value, CellStyle style)
Creates a cell, gives it a value, and applies a style if provided
(创建一个单元格,给它一个值,并应用样式(如果提供))
|
static Cell |
getCell(Row row, int columnIndex)
Get a specific cell from a row.
(从行中获取特定单元格。)
|
static Row |
getRow(int rowIndex, Sheet sheet)
Get a row from the spreadsheet, and create it if it doesn't exist.
(从电子表格中获取一行,如果它不存在则创建它。)
|
static void |
setAlignment(Cell cell, HorizontalAlignment align)
Take a cell, and align it.
(取一个单元格,并对齐它。)
|
static void |
setCellStyleProperties(Cell cell, java.util.Map<java.lang.String,java.lang.Object> properties)
This method attempts to find an existing CellStyle that matches the
cell 's current style plus styles properties in
properties .
(此方法尝试在属性中查找与单元格的当前样式和样式属性相匹配的现有 CellStyle。)
|
static void |
setCellStyleProperty(Cell cell, java.lang.String propertyName, java.lang.Object propertyValue)
This method attempts to find an existing CellStyle that matches the
cell 's current style plus a single style property
propertyName with value
propertyValue .
(此方法尝试查找与单元格的当前样式相匹配的现有 CellStyle 以及具有值 propertyValue 的单个样式属性 propertyName。)
|
static void |
setFont(Cell cell, Font font)
Take a cell, and apply a font to it
(取一个单元格,并为其应用字体)
|
static void |
setVerticalAlignment(Cell cell, VerticalAlignment align)
Take a cell, and vertically align it.
(取一个单元格,并垂直对齐它。)
|
static Cell |
translateUnicodeValues(Cell cell)
Looks for text in the cell that should be unicode, like α and provides the unicode version of it.
(在单元格中查找应该是 unicode 的文本,例如 α 并提供它的 unicode 版本。)
|
public static final java.lang.String ALIGNMENT
public static final java.lang.String BORDER_BOTTOM
public static final java.lang.String BORDER_LEFT
public static final java.lang.String BORDER_RIGHT
public static final java.lang.String BORDER_TOP
public static final java.lang.String BOTTOM_BORDER_COLOR
public static final java.lang.String LEFT_BORDER_COLOR
public static final java.lang.String RIGHT_BORDER_COLOR
public static final java.lang.String TOP_BORDER_COLOR
public static final java.lang.String DATA_FORMAT
public static final java.lang.String FILL_BACKGROUND_COLOR
public static final java.lang.String FILL_FOREGROUND_COLOR
public static final java.lang.String FILL_PATTERN
public static final java.lang.String FONT
public static final java.lang.String HIDDEN
public static final java.lang.String INDENTION
public static final java.lang.String LOCKED
public static final java.lang.String ROTATION
public static final java.lang.String VERTICAL_ALIGNMENT
public static final java.lang.String WRAP_TEXT
public static Row getRow(int rowIndex, Sheet sheet)
rowIndex
- The 0 based row number
(rowIndex - 基于 0 的行号)
sheet
- The sheet that the row is part of.
(sheet - 该行所属的工作表。)
public static Cell getCell(Row row, int columnIndex)
row
- The row that the cell is part of
(row - 单元格所在的行)
columnIndex
- The column index that the cell is in.
(columnIndex - 单元格所在的列索引。)
public static Cell createCell(Row row, int column, java.lang.String value, CellStyle style)
row
- the row to create the cell in
(row - 在其中创建单元格的行)
column
- the column index to create the cell in
(column - 要在其中创建单元格的列索引)
value
- The value of the cell
(value - 单元格的值)
style
- If the style is not null, then set
(style - 如果样式不为空,则设置)
public static Cell createCell(Row row, int column, java.lang.String value)
row
- the row to create the cell in
(row - 在其中创建单元格的行)
column
- the column index to create the cell in
(column - 要在其中创建单元格的列索引)
value
- The value of the cell
(value - 单元格的值)
public static void setAlignment(Cell cell, HorizontalAlignment align)
cell
- the cell to set the alignment for
(cell - 要为其设置对齐方式的单元格)
align
- the horizontal alignment to use.
(align - 要使用的水平对齐方式。)
for alignment options
public static void setVerticalAlignment(Cell cell, VerticalAlignment align)
cell
- the cell to set the alignment for
(cell - 要为其设置对齐方式的单元格)
align
- the vertical alignment to use.
(align - 要使用的垂直对齐方式。)
for alignment options
public static void setFont(Cell cell, Font font)
cell
- the cell to set the alignment for
(cell - 要为其设置对齐方式的单元格)
font
- The Font that you want to set.
(font - 要设置的字体。)
java.lang.IllegalArgumentException
- if
font and
cell do not belong to the same workbook
(java.lang.IllegalArgumentException - 如果字体和单元格不属于同一个工作簿)
public static void setCellStyleProperties(Cell cell, java.util.Map<java.lang.String,java.lang.Object> properties)
This method attempts to find an existing CellStyle that matches the cell
's current style plus styles properties in properties
. A new style is created if the workbook does not contain a matching style.
Modifies the cell style of cell
without affecting other cells that use the same style.
This is necessary because Excel has an upper limit on the number of styles that it supports.
This function is more efficient than multiple calls to setCellStyleProperty(org.apache.poi.ss.usermodel.Cell, String, Object)
if adding multiple cell styles.
For performance reasons, if this is the only cell in a workbook that uses a cell style, this method does NOT remove the old style from the workbook.
(此方法尝试在属性中查找与单元格的当前样式和样式属性相匹配的现有 CellStyle。如果工作簿不包含匹配的样式,则会创建新样式。修改单元格的单元格样式,而不影响其他使用相同样式的单元格。这是必要的,因为 Excel 对其支持的样式数量有上限。如果添加多个单元格样式,此函数比多次调用 setCellStyleProperty(org.apache.poi.ss.usermodel.Cell, String, Object) 更有效。出于性能原因,如果这是工作簿中唯一使用单元格样式的单元格,则此方法不会从工作簿中删除旧样式。)cell
- The cell to change the style of
(cell - 要更改其样式的单元格)
properties
- The properties to be added to a cell style, as {propertyName: propertyValue}.
(properties - 要添加到单元格样式的属性,如 {propertyName: propertyValue}。)
public static void setCellStyleProperty(Cell cell, java.lang.String propertyName, java.lang.Object propertyValue)
This method attempts to find an existing CellStyle that matches the cell
's current style plus a single style property propertyName
with value propertyValue
. A new style is created if the workbook does not contain a matching style.
Modifies the cell style of cell
without affecting other cells that use the same style.
If setting more than one cell style property on a cell, use setCellStyleProperties(org.apache.poi.ss.usermodel.Cell, Map)
, which is faster and does not add unnecessary intermediate CellStyles to the workbook.
cell
- The cell that is to be changed.
(cell - 要更改的单元格。)
propertyName
- The name of the property that is to be changed.
(propertyName - 要更改的属性的名称。)
propertyValue
- The value of the property that is to be changed.
(propertyValue - 要更改的属性的值。)
public static Cell translateUnicodeValues(Cell cell)
cell
- The cell to check for unicode values
(cell - 检查 unicode 值的单元格)
Copyright 2021 The Apache Software Foundation or its licensors, as applicable.