Class XSSFCellStyle
- All Implemented Interfaces:
CellStyle
-
Constructor Summary
ConstructorsConstructorDescriptionXSSFCellStyle(int cellXfId, int cellStyleXfId, StylesTable stylesSource, ThemesTable theme) Creates a Cell Style from the supplied partsXSSFCellStyle(StylesTable stylesSource) Creates an empty Cell Style -
Method Summary
Modifier and TypeMethodDescriptionclone()Make a copy of this style.voidcloneStyleFrom(CellStyle source) Clones all the style information from another XSSFCellStyle, onto this one.booleanChecks is the supplied style is equal to this styleget the type of horizontal alignment for the cellget the type of horizontal alignment for the cellget the type of border to use for the bottom border of the cellget the type of border to use for the bottom border of the cellGets border colorget the type of border to use for the left border of the cellget the type of border to use for the left border of the cellget the type of border to use for the right border of the cellget the type of border to use for the right border of the cellget the type of border to use for the top border of the cellget the type of border to use for the top border of the cellshortGet the color to use for the bottom border
Color is optional.Get the color to use for the bottom border as aXSSFColorprotected XSSFCellAlignmentget the cellAlignment object to use for manage alignmentorg.openxmlformats.schemas.spreadsheetml.x2006.main.CTXfUsed so that StylesSource can figure out our locationshortGet the index of the number format (numFmt) record used by this cell format.Get the contents of the format string, by looking up the StylesSourceshortGet the background fill color.Gets the color object representing the current background fill, resolving indexes using the supplied workbook.Get the background fill color.shortGet the foreground fill color.Gets the color object representing the current foreground fill, resolving indexes using the supplied workbook.Get the foreground fill color.Get the fill patternGet the fill patterngetFont()Gets the font for this styleshortDeprecated.intGets the index of the font for this stylebooleanGet whether the cell's using this style are to be hiddenshortGet the number of spaces to indent the text in the cellshortgetIndex()Get the index within the StylesTable (sequence within the collection of CTXf elements)shortGet the color to use for the left borderGet the color to use for the left borderbooleanGet whether the cell's using this style are lockedbooleanIs "Quote Prefix" or "123 Prefix" enabled for the cell?Get reading order of the cellshortGet the color to use for the right borderGet the color to use for the right bordershortGet the degree of rotation for the text in the cellbooleanShould the Cell be auto-sized by Excel to shrink it to fit if this text is too long?org.openxmlformats.schemas.spreadsheetml.x2006.main.CTXfUsed so that StylesSource can figure out our locationshortGet the color to use for the top borderGet the color to use for the top borderprotected intWorkaround for places where we need to support more than 32767 cell styles, ideally the main getIndex() and others would return int, not short, but that would affect some public APIsget the type of vertical alignment for the cellget the type of vertical alignment for the cellbooleanWhether the text should be wrappedinthashCode()Returns a hash code value for the object.voidsetAlignment(HorizontalAlignment align) Set the type of horizontal alignment for the cellvoidsetBorderBottom(BorderStyle border) Set the type of border to use for the bottom border of the cellvoidsetBorderColor(XSSFCellBorder.BorderSide side, XSSFColor color) Set the color to use for the selected bordervoidsetBorderLeft(BorderStyle border) Set the type of border to use for the left border of the cellvoidsetBorderRight(BorderStyle border) Set the type of border to use for the right border of the cellvoidsetBorderTop(BorderStyle border) Set the type of border to use for the top border of the cellvoidsetBottomBorderColor(short color) Set the color to use for the bottom bordervoidsetBottomBorderColor(XSSFColor color) Set the color to use for the bottom bordervoidsetDataFormat(int fmt) Set the index of a data formatvoidsetDataFormat(short fmt) Set the index of a data formatvoidsetFillBackgroundColor(short bg) Set the background fill color represented as a indexed color value.voidsetFillBackgroundColor(XSSFColor color) Set the background fill color represented as aXSSFColorvalue.voidsetFillForegroundColor(short fg) Set the foreground fill color as a indexed color value
Note: Ensure Foreground color is set prior to background color.voidsetFillForegroundColor(XSSFColor color) Set the foreground fill color represented as aXSSFColorvalue.voidsetFillPattern(FillPatternType pattern) This element is used to specify cell fill information for pattern and solid color cell fills.voidSet the font for this stylevoidsetHidden(boolean hidden) Set the cell's using this style to be hiddenvoidsetIndention(short indent) Set the number of spaces to indent the text in the cellvoidsetLeftBorderColor(short color) Set the color to use for the left border as a indexed color valuevoidsetLeftBorderColor(XSSFColor color) Set the color to use for the left border as aXSSFColorvaluevoidsetLocked(boolean locked) Set the cell's using this style to be lockedvoidsetQuotePrefixed(boolean quotePrefix) Turn on or off "Quote Prefix" or "123 Prefix" for the style, which is used to tell Excel that the thing which looks like a number or a formula shouldn't be treated as on.voidsetReadingOrder(ReadingOrder order) Set reading order for the cellvoidsetRightBorderColor(short color) Set the color to use for the right bordervoidsetRightBorderColor(XSSFColor color) Set the color to use for the right border as aXSSFColorvaluevoidsetRotation(short rotation) Set the degree of rotation for the text in the cellvoidsetShrinkToFit(boolean shrinkToFit) Controls if the Cell should be auto-sized to shrink to fit if the text is too longvoidsetTopBorderColor(short color) Set the color to use for the top bordervoidsetTopBorderColor(XSSFColor color) Set the color to use for the top border as aXSSFColorvaluevoidSet the type of vertical alignment for the cellvoidsetWrapText(boolean wrapped) Set whether the text should be wrapped.voidVerifies that this style belongs to the supplied Workbook Styles Source.
-
Constructor Details
-
XSSFCellStyle
Creates a Cell Style from the supplied parts- Parameters:
cellXfId- The main XF for the cell. Must be a valid 0-based index into the XF tablecellStyleXfId- Optional, style xf. A value of-1means no xf.stylesSource- Styles Source to work off
-
XSSFCellStyle
Creates an empty Cell Style
-
-
Method Details
-
getCoreXf
Used so that StylesSource can figure out our location -
getStyleXf
Used so that StylesSource can figure out our location -
verifyBelongsToStylesSource
Verifies that this style belongs to the supplied Workbook Styles Source. Will throw an exception if it belongs to a different one. This is normally called when trying to assign a style to a cell, to ensure the cell and the style are from the same workbook (if they're not, it won't work)- Throws:
IllegalArgumentException- if there's a workbook mis-match
-
cloneStyleFrom
Clones all the style information from another XSSFCellStyle, onto this one. This XSSFCellStyle will then have all the same properties as the source, but the two may be edited independently. Any stylings on this XSSFCellStyle will be lost! The source XSSFCellStyle could be from another XSSFWorkbook if you like. This allows you to copy styles from one XSSFWorkbook to another.- Specified by:
cloneStyleFromin interfaceCellStyle
-
getAlignment
Description copied from interface:CellStyleget the type of horizontal alignment for the cell- Specified by:
getAlignmentin interfaceCellStyle- Returns:
- align - the type of alignment
-
getAlignmentEnum
Description copied from interface:CellStyleget the type of horizontal alignment for the cell- Specified by:
getAlignmentEnumin interfaceCellStyle- Returns:
- align - the type of alignment
-
getBorderBottom
Description copied from interface:CellStyleget the type of border to use for the bottom border of the cell- Specified by:
getBorderBottomin interfaceCellStyle- Returns:
- border type
-
getBorderBottomEnum
Description copied from interface:CellStyleget the type of border to use for the bottom border of the cell- Specified by:
getBorderBottomEnumin interfaceCellStyle- Returns:
- border type
-
getBorderLeft
Description copied from interface:CellStyleget the type of border to use for the left border of the cell- Specified by:
getBorderLeftin interfaceCellStyle- Returns:
- border type
-
getBorderLeftEnum
Description copied from interface:CellStyleget the type of border to use for the left border of the cell- Specified by:
getBorderLeftEnumin interfaceCellStyle- Returns:
- border type
-
getBorderRight
Description copied from interface:CellStyleget the type of border to use for the right border of the cell- Specified by:
getBorderRightin interfaceCellStyle- Returns:
- border type
-
getBorderRightEnum
Description copied from interface:CellStyleget the type of border to use for the right border of the cell- Specified by:
getBorderRightEnumin interfaceCellStyle- Returns:
- border type
-
getBorderTop
Description copied from interface:CellStyleget the type of border to use for the top border of the cell- Specified by:
getBorderTopin interfaceCellStyle- Returns:
- border type
-
getBorderTopEnum
Description copied from interface:CellStyleget the type of border to use for the top border of the cell- Specified by:
getBorderTopEnumin interfaceCellStyle- Returns:
- border type
-
getBottomBorderColor
public short getBottomBorderColor()Get the color to use for the bottom border
Color is optional. When missing, IndexedColors.AUTOMATIC is implied.- Specified by:
getBottomBorderColorin interfaceCellStyle- Returns:
- the index of the color definition, default value is
IndexedColors.AUTOMATIC - See Also:
-
getBottomBorderXSSFColor
Get the color to use for the bottom border as aXSSFColor- Returns:
- the used color or
nullif not set
-
getDataFormat
public short getDataFormat()Get the index of the number format (numFmt) record used by this cell format.- Specified by:
getDataFormatin interfaceCellStyle- Returns:
- the index of the number format
- See Also:
-
getDataFormatString
Get the contents of the format string, by looking up the StylesSource- Specified by:
getDataFormatStringin interfaceCellStyle- Returns:
- the number format string
-
getFillBackgroundColor
public short getFillBackgroundColor()Get the background fill color.Note - many cells are actually filled with a foreground fill, not a background fill - see
getFillForegroundColor()- Specified by:
getFillBackgroundColorin interfaceCellStyle- Returns:
- fill color, default value is
IndexedColors.AUTOMATIC - See Also:
-
getFillBackgroundColorColor
Description copied from interface:CellStyleGets the color object representing the current background fill, resolving indexes using the supplied workbook. This will work for both indexed and rgb defined colors.- Specified by:
getFillBackgroundColorColorin interfaceCellStyle
-
getFillBackgroundXSSFColor
Get the background fill color.Note - many cells are actually filled with a foreground fill, not a background fill - see
getFillForegroundColor()- Returns:
- XSSFColor - fill color or
nullif not set - See Also:
-
getFillForegroundColor
public short getFillForegroundColor()Get the foreground fill color.Many cells are filled with this, instead of a background color (
getFillBackgroundColor())- Specified by:
getFillForegroundColorin interfaceCellStyle- Returns:
- fill color, default value is
IndexedColors.AUTOMATIC - See Also:
-
getFillForegroundColorColor
Description copied from interface:CellStyleGets the color object representing the current foreground fill, resolving indexes using the supplied workbook. This will work for both indexed and rgb defined colors.- Specified by:
getFillForegroundColorColorin interfaceCellStyle
-
getFillForegroundXSSFColor
Get the foreground fill color.- Returns:
- XSSFColor - fill color or
nullif not set
-
getFillPattern
Description copied from interface:CellStyleGet the fill pattern- Specified by:
getFillPatternin interfaceCellStyle- Returns:
- the fill pattern, default value is
FillPatternType.NO_FILL
-
getFillPatternEnum
Description copied from interface:CellStyleGet the fill pattern- Specified by:
getFillPatternEnumin interfaceCellStyle- Returns:
- the fill pattern, default value is
FillPatternType.NO_FILL
-
getFont
Gets the font for this style- Returns:
- Font - font
-
getFontIndex
Deprecated.Gets the index of the font for this style- Specified by:
getFontIndexin interfaceCellStyle- Returns:
- short - font index
- See Also:
-
getFontIndexAsInt
public int getFontIndexAsInt()Gets the index of the font for this style- Specified by:
getFontIndexAsIntin interfaceCellStyle- Returns:
- short - font index
- Since:
- 4.0.0
- See Also:
-
getHidden
public boolean getHidden()Get whether the cell's using this style are to be hidden -
getIndention
public short getIndention()Get the number of spaces to indent the text in the cell- Specified by:
getIndentionin interfaceCellStyle- Returns:
- indent - number of spaces
-
getIndex
public short getIndex()Get the index within the StylesTable (sequence within the collection of CTXf elements) -
getUIndex
protected int getUIndex()Workaround for places where we need to support more than 32767 cell styles, ideally the main getIndex() and others would return int, not short, but that would affect some public APIs- Returns:
- unique index number of the underlying record this style represents, as an int (always positive)
-
getLeftBorderColor
public short getLeftBorderColor()Get the color to use for the left border- Specified by:
getLeftBorderColorin interfaceCellStyle- Returns:
- the index of the color definition, default value is
IndexedColors.BLACK - See Also:
-
getLeftBorderXSSFColor
Get the color to use for the left border- Returns:
- the index of the color definition or
nullif not set - See Also:
-
getLocked
public boolean getLocked()Get whether the cell's using this style are locked -
getQuotePrefixed
public boolean getQuotePrefixed()Is "Quote Prefix" or "123 Prefix" enabled for the cell?- Specified by:
getQuotePrefixedin interfaceCellStyle
-
getRightBorderColor
public short getRightBorderColor()Get the color to use for the right border- Specified by:
getRightBorderColorin interfaceCellStyle- Returns:
- the index of the color definition, default value is
IndexedColors.BLACK - See Also:
-
getRightBorderXSSFColor
Get the color to use for the right border- Returns:
- the used color or
nullif not set
-
getRotation
public short getRotation()Get the degree of rotation for the text in the cellExpressed in degrees. Values range from 0 to 180. The first letter of the text is considered the center-point of the arc.
For 0 - 90, the value represents degrees above horizon. For 91-180 the degrees below the horizon is calculated as:
[degrees below horizon] = 90 - textRotation.- Specified by:
getRotationin interfaceCellStyle- Returns:
- rotation degrees (between 0 and 180 degrees)
-
getShrinkToFit
public boolean getShrinkToFit()Description copied from interface:CellStyleShould the Cell be auto-sized by Excel to shrink it to fit if this text is too long?- Specified by:
getShrinkToFitin interfaceCellStyle
-
getTopBorderColor
public short getTopBorderColor()Get the color to use for the top border- Specified by:
getTopBorderColorin interfaceCellStyle- Returns:
- the index of the color definition, default value is
IndexedColors.BLACK - See Also:
-
getTopBorderXSSFColor
Get the color to use for the top border- Returns:
- the used color or
nullif not set
-
getVerticalAlignment
Description copied from interface:CellStyleget the type of vertical alignment for the cell- Specified by:
getVerticalAlignmentin interfaceCellStyle- Returns:
- align the type of alignment
-
getVerticalAlignmentEnum
Description copied from interface:CellStyleget the type of vertical alignment for the cell- Specified by:
getVerticalAlignmentEnumin interfaceCellStyle- Returns:
- align the type of alignment
-
getWrapText
public boolean getWrapText()Whether the text should be wrapped- Specified by:
getWrapTextin interfaceCellStyle- Returns:
- a boolean value indicating if the text in a cell should be line-wrapped within the cell.
-
setAlignment
Set the type of horizontal alignment for the cell- Specified by:
setAlignmentin interfaceCellStyle- Parameters:
align- - the type of alignment
-
setBorderBottom
Set the type of border to use for the bottom border of the cell- Specified by:
setBorderBottomin interfaceCellStyle- Parameters:
border- - type of border to use- Since:
- POI 3.15
- See Also:
-
setBorderLeft
Set the type of border to use for the left border of the cell- Specified by:
setBorderLeftin interfaceCellStyle- Parameters:
border- the type of border to use- Since:
- POI 3.15
-
setBorderRight
Set the type of border to use for the right border of the cell- Specified by:
setBorderRightin interfaceCellStyle- Parameters:
border- the type of border to use- Since:
- POI 3.15
-
setBorderTop
Set the type of border to use for the top border of the cell- Specified by:
setBorderTopin interfaceCellStyle- Parameters:
border- the type of border to use- Since:
- POI 3.15
-
setBottomBorderColor
public void setBottomBorderColor(short color) Set the color to use for the bottom border- Specified by:
setBottomBorderColorin interfaceCellStyle- Parameters:
color- the index of the color definition- See Also:
-
setBottomBorderColor
Set the color to use for the bottom border- Parameters:
color- the color to use, null means no color
-
setDataFormat
public void setDataFormat(short fmt) Set the index of a data format- Specified by:
setDataFormatin interfaceCellStyle- Parameters:
fmt- the index of a data format- See Also:
-
setDataFormat
public void setDataFormat(int fmt) Set the index of a data format- Parameters:
fmt- the index of a data format
-
setFillBackgroundColor
Set the background fill color represented as aXSSFColorvalue.For example:
cs.setFillPattern(XSSFCellStyle.FINE_DOTS ); cs.setFillBackgroundXSSFColor(new XSSFColor(java.awt.Color.RED));
optionally a Foreground and background fill can be applied: Note: Ensure Foreground color is set prior to backgroundcs.setFillPattern(XSSFCellStyle.FINE_DOTS ); cs.setFillForegroundColor(new XSSFColor(java.awt.Color.BLUE)); cs.setFillBackgroundColor(new XSSFColor(java.awt.Color.GREEN));
or, for the special case of SOLID_FILL:cs.setFillPattern(XSSFCellStyle.SOLID_FOREGROUND ); cs.setFillForegroundColor(new XSSFColor(java.awt.Color.GREEN));
It is necessary to set the fill style in order for the color to be shown in the cell.- Parameters:
color- - the color to use
-
setFillBackgroundColor
public void setFillBackgroundColor(short bg) Set the background fill color represented as a indexed color value.For example:
cs.setFillPattern(XSSFCellStyle.FINE_DOTS ); cs.setFillBackgroundXSSFColor(IndexedColors.RED.getIndex());
optionally a Foreground and background fill can be applied: Note: Ensure Foreground color is set prior to backgroundcs.setFillPattern(XSSFCellStyle.FINE_DOTS ); cs.setFillForegroundColor(IndexedColors.BLUE.getIndex()); cs.setFillBackgroundColor(IndexedColors.RED.getIndex());
or, for the special case of SOLID_FILL:cs.setFillPattern(XSSFCellStyle.SOLID_FOREGROUND ); cs.setFillForegroundColor(IndexedColors.RED.getIndex());
It is necessary to set the fill style in order for the color to be shown in the cell.- Specified by:
setFillBackgroundColorin interfaceCellStyle- Parameters:
bg- - the color to use- See Also:
-
setFillForegroundColor
Set the foreground fill color represented as aXSSFColorvalue.
Note: Ensure Foreground color is set prior to background color.- Parameters:
color- the color to use- See Also:
-
setFillForegroundColor
public void setFillForegroundColor(short fg) Set the foreground fill color as a indexed color value
Note: Ensure Foreground color is set prior to background color.- Specified by:
setFillForegroundColorin interfaceCellStyle- Parameters:
fg- the color to use- See Also:
-
setReadingOrder
Set reading order for the cell- Parameters:
order- - the reading order
-
getReadingOrder
Get reading order of the cell- Returns:
- ReadingOrder - the reading order
-
setFillPattern
This element is used to specify cell fill information for pattern and solid color cell fills. For solid cell fills (no pattern), foreground color is used is used. For cell fills with patterns specified, then the cell fill color is specified by the background color element.- Specified by:
setFillPatternin interfaceCellStyle- Parameters:
pattern- the fill pattern to use- See Also:
-
setFont
Set the font for this style -
setHidden
public void setHidden(boolean hidden) Set the cell's using this style to be hidden -
setIndention
public void setIndention(short indent) Set the number of spaces to indent the text in the cell- Specified by:
setIndentionin interfaceCellStyle- Parameters:
indent- - number of spaces
-
setLeftBorderColor
public void setLeftBorderColor(short color) Set the color to use for the left border as a indexed color value- Specified by:
setLeftBorderColorin interfaceCellStyle- Parameters:
color- the index of the color definition- See Also:
-
setLeftBorderColor
Set the color to use for the left border as aXSSFColorvalue- Parameters:
color- the color to use
-
setLocked
public void setLocked(boolean locked) Set the cell's using this style to be locked -
setQuotePrefixed
public void setQuotePrefixed(boolean quotePrefix) Turn on or off "Quote Prefix" or "123 Prefix" for the style, which is used to tell Excel that the thing which looks like a number or a formula shouldn't be treated as on.- Specified by:
setQuotePrefixedin interfaceCellStyle
-
setRightBorderColor
public void setRightBorderColor(short color) Set the color to use for the right border- Specified by:
setRightBorderColorin interfaceCellStyle- Parameters:
color- the index of the color definition- See Also:
-
setRightBorderColor
Set the color to use for the right border as aXSSFColorvalue- Parameters:
color- the color to use
-
setRotation
public void setRotation(short rotation) Set the degree of rotation for the text in the cellExpressed in degrees. Values range from 0 to 180. The first letter of the text is considered the center-point of the arc.
Note: HSSF uses values from -90 to 90 degrees, whereas XSSF uses values from 0 to 180 degrees. The implementations of this method will map between these two value-ranges accordingly, however the corresponding getter is returning values in the range mandated by the current type of Excel file-format that this CellStyle is applied to.
For 0 - 90, the value represents degrees above horizon. For 91-180 the degrees below the horizon is calculated as:
[degrees below horizon] = 90 - textRotation.- Specified by:
setRotationin interfaceCellStyle- Parameters:
rotation- - the rotation degrees (between 0 and 180 degrees)
-
setTopBorderColor
public void setTopBorderColor(short color) Set the color to use for the top border- Specified by:
setTopBorderColorin interfaceCellStyle- Parameters:
color- the index of the color definition- See Also:
-
setTopBorderColor
Set the color to use for the top border as aXSSFColorvalue- Parameters:
color- the color to use
-
setVerticalAlignment
Set the type of vertical alignment for the cell- Specified by:
setVerticalAlignmentin interfaceCellStyle- Parameters:
align- - the type of alignment
-
setWrapText
public void setWrapText(boolean wrapped) Set whether the text should be wrapped.Setting this flag to
truemake all content visible whithin a cell by displaying it on multiple lines- Specified by:
setWrapTextin interfaceCellStyle- Parameters:
wrapped- a boolean value indicating if the text in a cell should be line-wrapped within the cell.
-
getBorderColor
Gets border color- Parameters:
side- the border side- Returns:
- the used color
-
setBorderColor
Set the color to use for the selected border- Parameters:
side- - where to apply the color definitioncolor- - the color to use
-
setShrinkToFit
public void setShrinkToFit(boolean shrinkToFit) Description copied from interface:CellStyleControls if the Cell should be auto-sized to shrink to fit if the text is too long- Specified by:
setShrinkToFitin interfaceCellStyle
-
getCellAlignment
get the cellAlignment object to use for manage alignment- Returns:
- XSSFCellAlignment - cell alignment
-
hashCode
public int hashCode()Returns a hash code value for the object. The hash is derived from the underlying CTXf bean. -
equals
Checks is the supplied style is equal to this style -
clone
Make a copy of this style. The underlying CTXf bean is cloned, the references to fills and borders remain.
-