Top Methods
org.apache.poi.ss.usermodel

public Interface CellStyle

Known Direct Implementers
org.apache.poi.hssf.usermodel.HSSFCellStyle
Imports
org.apache.poi.util.Removal

Method Summary

Modifier and TypeMethod and Description
public void
cloneStyleFrom(CellStyle source)

Clones all the style information from another CellStyle, onto this one.

public HorizontalAlignment

Returns:

align - the type of alignment
getAlignment
()

get the type of horizontal alignment for the cell

public BorderStyle

Returns:

border type
getBorderBottom
()

get the type of border to use for the bottom border of the cell

public BorderStyle

Returns:

border type
getBorderLeft
()

get the type of border to use for the left border of the cell

public BorderStyle

Returns:

border type
getBorderRight
()

get the type of border to use for the right border of the cell

public BorderStyle

Returns:

border type
getBorderTop
()

get the type of border to use for the top border of the cell

public short

Returns:

the index of the color definition
getBottomBorderColor
()

get the color to use for the left border

public short
getDataFormat()

get the index of the data format.

public String
getDataFormatString()

Get the format string

public short

Returns:

fill color index, or 0 if not indexed (XSSF only)
getFillBackgroundColor
()

get the background fill color, if the fill is defined with an indexed color.

public Color
getFillBackgroundColorColor()

Gets the color object representing the current background fill, resolving indexes using the supplied workbook.

public short

Returns:

fill color, or 0 if not indexed (XSSF only)
getFillForegroundColor
()

get the foreground fill color, if the fill is defined with an indexed color.

public Color
getFillForegroundColorColor()

Gets the color object representing the current foreground fill, resolving indexes using the supplied workbook.

public FillPatternType

Returns:

the fill pattern, default value is FillPatternType#NO_FILL
getFillPattern
()

Get the fill pattern

public int
getFontIndex()

gets the index of the font for this style

public int
getFontIndexAsInt()
Deprecated use getFontIndex() instead

gets the index of the font for this style

public boolean

Returns:

hidden - whether the cell using this style should be hidden
getHidden
()

get whether the cell's using this style are to be hidden

public short

Returns:

indent - number of spaces
getIndention
()

get the number of spaces to indent the text in the cell

public short

Returns:

unique index number of the underlying record this style represents (probably you don't care unless you're comparing which one is which)
getIndex
()

get the index within the Workbook (sequence within the collection of ExtendedFormat objects)

public short
getLeftBorderColor()

get the color to use for the left border

public boolean

Returns:

hidden - whether the cell using this style should be locked
getLocked
()

get whether the cell's using this style are to be locked

public boolean
getQuotePrefixed()

Is "Quote Prefix" or "123 Prefix" enabled for the cell?

public short

Returns:

the index of the color definition
getRightBorderColor
()

get the color to use for the left border

public short

Returns:

rotation degrees (see note above)
getRotation
()

get the degree of rotation for the text in the cell.

public boolean
getShrinkToFit()

Should the Cell be auto-sized by Excel to shrink it to fit if this text is too long?

public short

Returns:

the index of the color definition
getTopBorderColor
()

get the color to use for the top border

public VerticalAlignment

Returns:

align the type of alignment
getVerticalAlignment
()

get the type of vertical alignment for the cell

public boolean

Returns:

wrap text or not
getWrapText
()

get whether the text should be wrapped

public void
setAlignment(HorizontalAlignment
- the type of alignment
align
)

set the type of horizontal alignment for the cell

public void
setBorderBottom(BorderStyle
type
border
)

set the type of border to use for the bottom border of the cell

public void
setBorderLeft(BorderStyle
type
border
)

set the type of border to use for the left border of the cell

public void
setBorderRight(BorderStyle
type
border
)

set the type of border to use for the right border of the cell

public void
setBorderTop(BorderStyle
type
border
)

set the type of border to use for the top border of the cell

public void
setBottomBorderColor(short
The index of the color definition
color
)

set the color to use for the bottom border

public void
setDataFormat(short fmt)

set the data format (must be a valid format).

public void
setFillBackgroundColor(short
color
bg
)

set the background fill color.

public void
setFillBackgroundColor(Color
org.apache.poi.ss.usermodel.Color to set
color
)

Set the background fill color.

public void
setFillForegroundColor(short
color
bg
)

set the foreground fill color

Note

Ensure Foreground color is set prior to background color.

public void
setFillForegroundColor(Color
org.apache.poi.ss.usermodel.Color to set
color
)

Set the foreground fill color.

public void
setFillPattern(FillPatternType
fill pattern (set to FillPatternType#SOLID_FOREGROUND to fill w/foreground color)
fp
)

setting to one fills the cell with the foreground color...

public void
setFont(Font
a font object created or retrieved from the Workbook object
font
)

set the font for this style

public void
setHidden(boolean
- whether the cell using this style should be hidden
hidden
)

set the cell's using this style to be hidden

public void
setIndention(short
- number of spaces
indent
)

set the number of spaces to indent the text in the cell

public void
setLeftBorderColor(short
The index of the color definition
color
)

set the color to use for the left border

public void
setLocked(boolean
- whether the cell using this style should be locked
locked
)

set the cell's using this style to be locked

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.

public void
setRightBorderColor(short
The index of the color definition
color
)

set the color to use for the right border

public void
setRotation(short
degrees (see note above)
rotation
)

set the degree of rotation for the text in the cell.

public void
setShrinkToFit(boolean shrinkToFit)

Controls if the Cell should be auto-sized to shrink to fit if the text is too long

public void
setTopBorderColor(short
The index of the color definition
color
)

set the color to use for the top border

public void
setVerticalAlignment(VerticalAlignment
the type of alignment
align
)

set the type of vertical alignment for the cell

public void
setWrapText(boolean
wrap text or not
wrapped
)

Set whether the text should be wrapped.

Method Detail

cloneStyleFromback to summary
public void cloneStyleFrom(CellStyle source)

Clones all the style information from another CellStyle, onto this one. This CellStyle will then have all the same properties as the source, but the two may be edited independently. Any stylings on this CellStyle will be lost! The source CellStyle could be from another Workbook if you like. This allows you to copy styles from one Workbook to another. However, both of the CellStyles will need to be of the same type (HSSFCellStyle or XSSFCellStyle)

getAlignmentback to summary
public HorizontalAlignment getAlignment()

get the type of horizontal alignment for the cell

Returns:HorizontalAlignment

align - the type of alignment

getBorderBottomback to summary
public BorderStyle getBorderBottom()

get the type of border to use for the bottom border of the cell

Returns:BorderStyle

border type

Since
POI 4.0.0
getBorderLeftback to summary
public BorderStyle getBorderLeft()

get the type of border to use for the left border of the cell

Returns:BorderStyle

border type

Since
POI 4.0.0
getBorderRightback to summary
public BorderStyle getBorderRight()

get the type of border to use for the right border of the cell

Returns:BorderStyle

border type

Since
POI 4.0.0
getBorderTopback to summary
public BorderStyle getBorderTop()

get the type of border to use for the top border of the cell

Returns:BorderStyle

border type

Since
POI 4.0.0
getBottomBorderColorback to summary
public short getBottomBorderColor()

get the color to use for the left border

Returns:short

the index of the color definition

getDataFormatback to summary
public short getDataFormat()

get the index of the data format. Built in formats are defined at BuiltinFormats.

See Also
DataFormat
getDataFormatStringback to summary
public String getDataFormatString()

Get the format string

getFillBackgroundColorback to summary
public short getFillBackgroundColor()

get the background fill color, if the fill is defined with an indexed color.

Returns:short

fill color index, or 0 if not indexed (XSSF only)

getFillBackgroundColorColorback to summary
public Color getFillBackgroundColorColor()

Gets the color object representing the current background fill, resolving indexes using the supplied workbook. This will work for both indexed and rgb defined colors.

getFillForegroundColorback to summary
public short getFillForegroundColor()

get the foreground fill color, if the fill is defined with an indexed color.

Returns:short

fill color, or 0 if not indexed (XSSF only)

getFillForegroundColorColorback to summary
public Color getFillForegroundColorColor()

Gets the color object representing the current foreground fill, resolving indexes using the supplied workbook. This will work for both indexed and rgb defined colors.

getFillPatternback to summary
public FillPatternType getFillPattern()

Get the fill pattern

Returns:FillPatternType

the fill pattern, default value is FillPatternType#NO_FILL

Since
POI 4.0.0
getFontIndexback to summary
public int getFontIndex()

gets the index of the font for this style

Since
5.0.0 (used to return a short value)
See Also
Workbook#getFontAt(int)
getFontIndexAsIntback to summary
public int getFontIndexAsInt()

Deprecated

use getFontIndex() instead

gets the index of the font for this style

Annotations
@Deprecated
@Removal
version:6.0.0
Since
4.0.0
See Also
Workbook#getFontAt(int)
getHiddenback to summary
public boolean getHidden()

get whether the cell's using this style are to be hidden

Returns:boolean

hidden - whether the cell using this style should be hidden

getIndentionback to summary
public short getIndention()

get the number of spaces to indent the text in the cell

Returns:short

indent - number of spaces

getIndexback to summary
public short getIndex()

get the index within the Workbook (sequence within the collection of ExtendedFormat objects)

Returns:short

unique index number of the underlying record this style represents (probably you don't care unless you're comparing which one is which)

getLeftBorderColorback to summary
public short getLeftBorderColor()

get the color to use for the left border

getLockedback to summary
public boolean getLocked()

get whether the cell's using this style are to be locked

Returns:boolean

hidden - whether the cell using this style should be locked

getQuotePrefixedback to summary
public boolean getQuotePrefixed()

Is "Quote Prefix" or "123 Prefix" enabled for the cell? Having this on is somewhat (but not completely, see IgnoredErrorType) like prefixing the cell value with a ' in Excel

getRightBorderColorback to summary
public short getRightBorderColor()

get the color to use for the left border

Returns:short

the index of the color definition

getRotationback to summary
public short getRotation()

get the degree of rotation for the text in the cell.

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 value-range as used by the type of Excel file-format that this CellStyle is applied to.

Returns:short

rotation degrees (see note above)

getShrinkToFitback to summary
public boolean getShrinkToFit()

Should the Cell be auto-sized by Excel to shrink it to fit if this text is too long?

getTopBorderColorback to summary
public short getTopBorderColor()

get the color to use for the top border

Returns:short

the index of the color definition

getVerticalAlignmentback to summary
public VerticalAlignment getVerticalAlignment()

get the type of vertical alignment for the cell

Returns:VerticalAlignment

align the type of alignment

getWrapTextback to summary
public boolean getWrapText()

get whether the text should be wrapped

Returns:boolean

wrap text or not

setAlignmentback to summary
public void setAlignment(HorizontalAlignment align)

set the type of horizontal alignment for the cell

Parameters
align:HorizontalAlignment

- the type of alignment

setBorderBottomback to summary
public void setBorderBottom(BorderStyle border)

set the type of border to use for the bottom border of the cell

Parameters
border:BorderStyle

type

Since
POI 3.15
setBorderLeftback to summary
public void setBorderLeft(BorderStyle border)

set the type of border to use for the left border of the cell

Parameters
border:BorderStyle

type

Since
POI 3.15
setBorderRightback to summary
public void setBorderRight(BorderStyle border)

set the type of border to use for the right border of the cell

Parameters
border:BorderStyle

type

Since
POI 3.15
setBorderTopback to summary
public void setBorderTop(BorderStyle border)

set the type of border to use for the top border of the cell

Parameters
border:BorderStyle

type

Since
POI 3.15
setBottomBorderColorback to summary
public void setBottomBorderColor(short color)

set the color to use for the bottom border

Parameters
color:short

The index of the color definition

setDataFormatback to summary
public void setDataFormat(short fmt)

set the data format (must be a valid format). Built in formats are defined at BuiltinFormats.

See Also
DataFormat
setFillBackgroundColorback to summary
public void setFillBackgroundColor(short bg)

set the background fill color.

Parameters
bg:short

color

setFillBackgroundColorback to summary
public void setFillBackgroundColor(Color color)

Set the background fill color. Uses a org.apache.poi.ss.usermodel.Color instead of an indexed color.

Parameters
color:Color

org.apache.poi.ss.usermodel.Color to set

Since
POI 5.2.3
setFillForegroundColorback to summary
public void setFillForegroundColor(short bg)

set the foreground fill color

Note

Ensure Foreground color is set prior to background color.

Parameters
bg:short

color

setFillForegroundColorback to summary
public void setFillForegroundColor(Color color)

Set the foreground fill color. Uses a org.apache.poi.ss.usermodel.Color instead of an indexed color.

Parameters
color:Color

org.apache.poi.ss.usermodel.Color to set

Since
POI 5.2.3
setFillPatternback to summary
public void setFillPattern(FillPatternType fp)

setting to one fills the cell with the foreground color... No idea about other values

Parameters
fp:FillPatternType

fill pattern (set to FillPatternType#SOLID_FOREGROUND to fill w/foreground color)

Since
POI 3.15 beta 3
setFontback to summary
public void setFont(Font font)

set the font for this style

Parameters
font:Font

a font object created or retrieved from the Workbook object

See Also
Workbook#createFont(), Workbook#getFontAt(int)
setHiddenback to summary
public void setHidden(boolean hidden)

set the cell's using this style to be hidden

Parameters
hidden:boolean

- whether the cell using this style should be hidden

setIndentionback to summary
public void setIndention(short indent)

set the number of spaces to indent the text in the cell

Parameters
indent:short

- number of spaces

setLeftBorderColorback to summary
public void setLeftBorderColor(short color)

set the color to use for the left border

Parameters
color:short

The index of the color definition

setLockedback to summary
public void setLocked(boolean locked)

set the cell's using this style to be locked

Parameters
locked:boolean

- whether the cell using this style should be locked

setQuotePrefixedback to summary
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. Turning this on is somewhat (but not completely, see IgnoredErrorType) like prefixing the cell value with a ' in Excel

setRightBorderColorback to summary
public void setRightBorderColor(short color)

set the color to use for the right border

Parameters
color:short

The index of the color definition

setRotationback to summary
public void setRotation(short rotation)

set the degree of rotation for the text in the cell.

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.

Parameters
rotation:short

degrees (see note above)

setShrinkToFitback to summary
public void setShrinkToFit(boolean shrinkToFit)

Controls if the Cell should be auto-sized to shrink to fit if the text is too long

setTopBorderColorback to summary
public void setTopBorderColor(short color)

set the color to use for the top border

Parameters
color:short

The index of the color definition

setVerticalAlignmentback to summary
public void setVerticalAlignment(VerticalAlignment align)

set the type of vertical alignment for the cell

Parameters
align:VerticalAlignment

the type of alignment

setWrapTextback to summary
public void setWrapText(boolean wrapped)

Set whether the text should be wrapped. Setting this flag to true make all content visible within a cell by displaying it on multiple lines

Parameters
wrapped:boolean

wrap text or not