Class CellUtil
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringDeprecated.as of POI 5.4.0.static final StringDeprecated.as of POI 5.4.0.static final StringDeprecated.as of POI 5.4.0.static final StringDeprecated.as of POI 5.4.0.static final StringDeprecated.as of POI 5.4.0.static final StringDeprecated.as of POI 5.4.0.static final StringDeprecated.as of POI 5.4.0.static final StringDeprecated.as of POI 5.4.0.static final StringDeprecated.as of POI 5.4.0.static final StringDeprecated.as of POI 5.4.0.static final StringDeprecated.as of POI 5.4.0.static final StringDeprecated.as of POI 5.4.0.static final StringDeprecated.as of POI 5.4.0.static final StringDeprecated.as of POI 5.4.0.static final StringDeprecated.as of POI 5.4.0.static final StringDeprecated.as of POI 5.4.0.static final StringDeprecated.as of POI 5.4.0.static final StringDeprecated.as of POI 5.4.0.static final StringDeprecated.as of POI 5.4.0.static final StringDeprecated.as of POI 5.4.0.static final StringDeprecated.as of POI 5.4.0.static final StringDeprecated.as of POI 5.4.0.static final StringDeprecated.as of POI 5.4.0.static final StringDeprecated.as of POI 5.4.0. -
Method Summary
Modifier and TypeMethodDescriptionstatic voidcloneStyle(CellStyle src, CellStyle dest, Workbook destWorkbook) Clones the style from one cell to another.static voidcopyCell(Cell srcCell, Cell destCell, CellCopyPolicy policy, CellCopyContext context) Copy cell value, formula and style, from srcCell per cell copy policy If srcCell is null, clears the cell value and cell style per cell copy policy.static CellcreateCell(Row row, int column, String value) Create a cell, and give it a value.static CellcreateCell(Row row, int column, String value, CellStyle style) Creates a cell, gives it a value, and applies a style if providedstatic CellGet a specific cell from a row.static EnumMap<CellPropertyType,Object> getFormatProperties(CellStyle style) Returns a map containing the format properties of the given cell style.static RowGet a row from the spreadsheet, and create it if it doesn't exist.static voidsetAlignment(Cell cell, HorizontalAlignment align) Take a cell, and align it.static voidsetCellStyleProperties(Cell cell, Map<String, Object> properties) Deprecated.as of POI 5.4.0.static voidsetCellStylePropertiesEnum(Cell cell, Map<CellPropertyType, Object> properties) This method attempts to find an existing CellStyle that matches thecell's current style plus styles properties inproperties.static voidsetCellStyleProperty(Cell cell, String propertyName, Object propertyValue) Deprecated.as of POI 5.4.0.static voidsetCellStyleProperty(Cell cell, CellPropertyType property, Object propertyValue) This method attempts to find an existing CellStyle that matches thecell's current style plus a single style propertypropertyNamewith valuepropertyValue.static voidTake a cell, and apply a font to itstatic voidsetVerticalAlignment(Cell cell, VerticalAlignment align) Take a cell, and vertically align it.static CelltranslateUnicodeValues(Cell cell) Looks for text in the cell that should be unicode, like α and provides the unicode version of it.
-
Field Details
-
ALIGNMENT
Deprecated.as of POI 5.4.0. UseCellPropertyType.ALIGNMENTinstead.- See Also:
-
BORDER_BOTTOM
Deprecated.as of POI 5.4.0. UseCellPropertyType.BORDER_BOTTOMinstead.- See Also:
-
BORDER_LEFT
Deprecated.as of POI 5.4.0. UseCellPropertyType.BORDER_LEFTinstead.- See Also:
-
BORDER_RIGHT
Deprecated.as of POI 5.4.0. UseCellPropertyType.BORDER_RIGHTinstead.- See Also:
-
BORDER_TOP
Deprecated.as of POI 5.4.0. UseCellPropertyType.BORDER_TOPinstead.- See Also:
-
BOTTOM_BORDER_COLOR
Deprecated.as of POI 5.4.0. UseCellPropertyType.BORDER_BOTTOMinstead.- See Also:
-
LEFT_BORDER_COLOR
Deprecated.as of POI 5.4.0. UseCellPropertyType.BOTTOM_BORDER_COLORinstead.- See Also:
-
RIGHT_BORDER_COLOR
Deprecated.as of POI 5.4.0. UseCellPropertyType.RIGHT_BORDER_COLORinstead.- See Also:
-
TOP_BORDER_COLOR
Deprecated.as of POI 5.4.0. UseCellPropertyType.TOP_BORDER_COLORinstead.- See Also:
-
DATA_FORMAT
Deprecated.as of POI 5.4.0. UseCellPropertyType.DATA_FORMATinstead.- See Also:
-
FILL_BACKGROUND_COLOR
Deprecated.as of POI 5.4.0. UseCellPropertyType.FILL_BACKGROUND_COLORinstead.- See Also:
-
FILL_FOREGROUND_COLOR
Deprecated.as of POI 5.4.0. UseCellPropertyType.FILL_FOREGROUND_COLORinstead.- See Also:
-
FILL_BACKGROUND_COLOR_COLOR
Deprecated.as of POI 5.4.0. UseCellPropertyType.FILL_BACKGROUND_COLOR_COLORinstead.- See Also:
-
FILL_FOREGROUND_COLOR_COLOR
Deprecated.as of POI 5.4.0. UseCellPropertyType.FILL_FOREGROUND_COLOR_COLORinstead.- See Also:
-
FILL_PATTERN
Deprecated.as of POI 5.4.0. UseCellPropertyType.FILL_PATTERNinstead.- See Also:
-
FONT
Deprecated.as of POI 5.4.0. UseCellPropertyType.FONTinstead.- See Also:
-
HIDDEN
Deprecated.as of POI 5.4.0. UseCellPropertyType.HIDDENinstead.- See Also:
-
INDENTION
Deprecated.as of POI 5.4.0. UseCellPropertyType.INDENTIONinstead.- See Also:
-
LOCKED
Deprecated.as of POI 5.4.0. UseCellPropertyType.LOCKEDinstead.- See Also:
-
ROTATION
Deprecated.as of POI 5.4.0. UseCellPropertyType.ROTATIONinstead.- See Also:
-
VERTICAL_ALIGNMENT
Deprecated.as of POI 5.4.0. UseCellPropertyType.VERTICAL_ALIGNMENTinstead.- See Also:
-
WRAP_TEXT
Deprecated.as of POI 5.4.0. UseCellPropertyType.WRAP_TEXTinstead.- See Also:
-
SHRINK_TO_FIT
Deprecated.as of POI 5.4.0. UseCellPropertyType.SHRINK_TO_FITinstead.- See Also:
-
QUOTE_PREFIXED
Deprecated.as of POI 5.4.0. UseCellPropertyType.QUOTE_PREFIXEDinstead.- 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.
-
copyCell
@Beta public static void copyCell(Cell srcCell, Cell destCell, CellCopyPolicy policy, CellCopyContext context) Copy cell value, formula and style, from srcCell per cell copy policy If srcCell is null, clears the cell value and cell style per cell copy policy. Note that if you are copying from a source cell from a different type of then you may need to disable style copying in theCellCopyPolicy(HSSF styles are not compatible with XSSF styles, for instance). This does not shift references in formulas. ThecopyRowFrommethod onXSSFRowandHSSFRowdoes attempt to shift references in formulas.- Parameters:
srcCell- The cell to take value, formula and style fromdestCell- The cell to copy topolicy- The policy for copying the information, seeCellCopyPolicycontext- The context for copying, seeCellCopyContext- Throws:
IllegalArgumentException- if copy cell style and srcCell is from a different workbookIllegalStateException- if srcCell hyperlink is not an instance ofDuplicatable- Since:
- 5.2.0
-
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:
- 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:
- 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- iffontandcelldo not belong to the same workbook
-
setCellStyleProperties
@Deprecated @Removal(version="7.0.0") public static void setCellStyleProperties(Cell cell, Map<String, Object> properties) Deprecated.as of POI 5.4.0. SeesetCellStylePropertiesEnum(Cell, Map)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
cellwithout 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(Cell, CellPropertyType, 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 {property: propertyValue}.- Since:
- 3.14 beta 2
-
setCellStylePropertiesEnum
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
cellwithout 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(Cell, CellPropertyType, 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 {property: propertyValue}.- Since:
- 5.4.0
-
setCellStyleProperty
This method attempts to find an existing CellStyle that matches the
cell's current style plus a single style propertypropertyNamewith valuepropertyValue. A new style is created if the workbook does not contain a matching style.Modifies the cell style of
cellwithout affecting other cells that use the same style.If setting more than one cell style property on a cell, use
setCellStylePropertiesEnum(Cell, Map), which is faster and does not add unnecessary intermediate CellStyles to the workbook.- Parameters:
cell- The cell that is to be changed.property- The name of the property that is to be changed.propertyValue- The value of the property that is to be changed.- Throws:
NullPointerException- ifcellorpropertyis null- Since:
- 5.4.0
-
setCellStyleProperty
@Deprecated @Removal(version="7.0.0") public static void setCellStyleProperty(Cell cell, String propertyName, Object propertyValue) Deprecated.as of POI 5.4.0. SeesetCellStyleProperty(Cell, CellPropertyType, Object)This method attempts to find an existing CellStyle that matches the
cell's current style plus a single style propertypropertyNamewith valuepropertyValue. A new style is created if the workbook does not contain a matching style.Modifies the cell style of
cellwithout affecting other cells that use the same style.If setting more than one cell style property on a cell, use
setCellStylePropertiesEnum(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.
-
getFormatProperties
Returns a map containing the format properties of the given cell style. The returned map is not tied tostyle, so subsequent changes tostylewill not modify the map, and changes to the returned map will not modify the cell style. The returned map is mutable.- Parameters:
style- cell style- Returns:
- map of format properties (CellPropertyType -> Object)
- Since:
- 5.5.0
- See Also:
-
setFormatProperties(CellStyle, Workbook, Map)
-
cloneStyle
Clones the style from one cell to another. For internal use only. Users should use the cloneStyleFrom method on CellStyle instead.- Parameters:
src- source cell styledest- destination cell styledestWorkbook- destination workbook (can be null but some font info will not be copied if null is passed)- Throws:
IllegalArgumentException- if source or destination styles are null- Since:
- 5.5.0
-
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
-