Class CellUtil
- Author:
- Eric Pugh epugh@upstate.com, (secondary) Avinash Kewalramani akewalramani@accelrys.com
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
-
Method Summary
Modifier and TypeMethodDescriptionstatic Cell
createCell
(Row row, int column, String value) Create a cell, and give it a value.static Cell
createCell
(Row row, int column, String value, CellStyle style) Creates a cell, gives it a value, and applies a style if providedstatic Cell
Get a specific cell from a row.static Row
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, Map<String, Object> properties) This method attempts to find an existing CellStyle that matches thecell
's current style plus styles properties inproperties
.static void
setCellStyleProperty
(Cell cell, String propertyName, Object propertyValue) This method attempts to find an existing CellStyle that matches thecell
's current style plus a single style propertypropertyName
with valuepropertyValue
.static void
Take a cell, and apply a font to itstatic 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.
-
Field Details
-
ALIGNMENT
- See Also:
-
BORDER_BOTTOM
- See Also:
-
BORDER_LEFT
- See Also:
-
BORDER_RIGHT
- See Also:
-
BORDER_TOP
- See Also:
-
BOTTOM_BORDER_COLOR
- See Also:
-
LEFT_BORDER_COLOR
- See Also:
-
RIGHT_BORDER_COLOR
- See Also:
-
TOP_BORDER_COLOR
- See Also:
-
DATA_FORMAT
- See Also:
-
FILL_BACKGROUND_COLOR
- See Also:
-
FILL_FOREGROUND_COLOR
- See Also:
-
FILL_PATTERN
- See Also:
-
FONT
- See Also:
-
HIDDEN
- See Also:
-
INDENTION
- See Also:
-
LOCKED
- See Also:
-
ROTATION
- See Also:
-
VERTICAL_ALIGNMENT
- See Also:
-
WRAP_TEXT
- See Also:
-
-
Method Details
-
getRow
Get a row from the spreadsheet, and create it if it doesn't exist.- Parameters:
rowIndex
- The 0 based row numbersheet
- The sheet that the row is part of.- Returns:
- The row indicated by the rowCounter
-
getCell
Get a specific cell from a row. If the cell doesn't exist, then create it.- Parameters:
row
- The row that the cell is part ofcolumnIndex
- The column index that the cell is in.- Returns:
- The cell indicated by the column.
-
createCell
Creates a cell, gives it a value, and applies a style if provided- Parameters:
row
- the row to create the cell incolumn
- the column index to create the cell invalue
- The value of the cellstyle
- If the style is not null, then set- Returns:
- A new Cell
-
createCell
Create a cell, and give it a value.- Parameters:
row
- the row to create the cell incolumn
- the column index to create the cell invalue
- The value of the cell- Returns:
- A new Cell.
-
setAlignment
Take a cell, and align it. This is superior to cell.getCellStyle().setAlignment(align) because this method will not modify the CellStyle object that may be referenced by multiple cells. Instead, this method will search for existing CellStyles that match the desired CellStyle, creating a new CellStyle with the desired style if no match exists.- Parameters:
cell
- the cell to set the alignment foralign
- the horizontal alignment to use.- Since:
- POI 3.15 beta 3
- See Also:
-
setVerticalAlignment
Take a cell, and vertically align it. This is superior to cell.getCellStyle().setVerticalAlignment(align) because this method will not modify the CellStyle object that may be referenced by multiple cells. Instead, this method will search for existing CellStyles that match the desired CellStyle, creating a new CellStyle with the desired style if no match exists.- Parameters:
cell
- the cell to set the alignment foralign
- the vertical alignment to use.- Since:
- POI 3.15 beta 3
- See Also:
-
setFont
Take a cell, and apply a font to it- Parameters:
cell
- the cell to set the alignment forfont
- The Font that you want to set.- Throws:
IllegalArgumentException
- if font and cell do not belong to the same workbook
-
setCellStyleProperties
This method attempts to find an existing CellStyle that matches the
cell
's current style plus styles properties inproperties
. 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.
- Parameters:
cell
- The cell to change the style ofproperties
- The properties to be added to a cell style, as {propertyName: propertyValue}.- Since:
- POI 3.14 beta 2
-
setCellStyleProperty
This method attempts to find an existing CellStyle that matches the
cell
's current style plus a single style propertypropertyName
with valuepropertyValue
. 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.- Parameters:
cell
- The cell that is to be changed.propertyName
- The name of the property that is to be changed.propertyValue
- The value of the property that is to be changed.
-
translateUnicodeValues
Looks for text in the cell that should be unicode, like α and provides the unicode version of it.- Parameters:
cell
- The cell to check for unicode values- Returns:
- translated to unicode
-