Package org.apache.poi.hssf.usermodel
Class HSSFCellStyle
java.lang.Object
org.apache.poi.hssf.usermodel.HSSFCellStyle
- All Implemented Interfaces:
CellStyle
High level representation of the style of a cell in a sheet of a workbook.
- See Also:
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
HSSFCellStyle
(short index, ExtendedFormatRecord rec, InternalWorkbook workbook) protected
HSSFCellStyle
(short index, ExtendedFormatRecord rec, HSSFWorkbook workbook) Creates new HSSFCellStyle why would you want to do this?? -
Method Summary
Modifier and TypeMethodDescriptionvoid
cloneStyleFrom
(HSSFCellStyle source) void
cloneStyleFrom
(CellStyle source) Clones all the style information from another HSSFCellStyle, onto this one.boolean
get 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 cellget 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 cellshort
get the color to use for the left bordershort
get the index of the formatGet the contents of the format string, by looking up the DataFormat against the bound workbookgetDataFormatString
(InternalWorkbook workbook) Get the contents of the format string, by looking up the DataFormat against the supplied low level workbookgetDataFormatString
(Workbook workbook) Get the contents of the format string, by looking up the DataFormat against the supplied workbookshort
Get the background fill color.Gets the color object representing the current background fill, resolving indexes using the supplied workbook.short
Get the foreground fill color.Gets the color object representing the current foreground fill, resolving indexes using the supplied workbook.Get the fill patternGet the fill patterngets the font for this styleshort
Deprecated.int
gets the index of the font for this styleboolean
get whether the cell's using this style are to be hiddenshort
get the number of spaces to indent the text in the cellshort
getIndex()
get the index within the HSSFWorkbook (sequence within the collection of ExtnededFormat objects)short
get the color to use for the left borderboolean
get whether the cell's using this style are to be lockedReturn the parent style for this cell style.boolean
Is "Quote Prefix" or "123 Prefix" enabled for the cell?short
Get the reading order, for RTL/LTR ordering of the text.short
get the color to use for the left bordershort
get the degree of rotation for the text in the cellboolean
Should the Cell be auto-sized by Excel to shrink it to fit if this text is too long?short
get the color to use for the top borderGets the name of the user defined style.get the type of vertical alignment for the cellget the type of vertical alignment for the cellboolean
get whether the text should be wrappedint
hashCode()
void
setAlignment
(HorizontalAlignment align) set the type of horizontal alignment for the cellvoid
setBorderBottom
(BorderStyle border) set the type of border to use for the bottom border of the cellvoid
setBorderLeft
(BorderStyle border) set the type of border to use for the left border of the cellvoid
setBorderRight
(BorderStyle border) set the type of border to use for the right border of the cellvoid
setBorderTop
(BorderStyle border) set the type of border to use for the top border of the cellvoid
setBottomBorderColor
(short color) set the color to use for the bottom bordervoid
setDataFormat
(short fmt) set the data format (must be a valid format)void
setFillBackgroundColor
(short bg) set the background fill color.void
setFillForegroundColor
(short bg) set the foreground fill color Note: Ensure Foreground color is set prior to background color.void
setting to one fills the cell with the foreground color...void
void
set the font for this stylevoid
setHidden
(boolean hidden) set the cell's using this style to be hiddenvoid
setIndention
(short indent) set the number of spaces to indent the text in the cellvoid
setLeftBorderColor
(short color) set the color to use for the left bordervoid
setLocked
(boolean locked) set the cell's using this style to be lockedvoid
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.void
setReadingOrder
(short order) Sets the reading order, for RTL/LTR ordering of the text.void
setRightBorderColor
(short color) set the color to use for the right bordervoid
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.void
setShrinkToFit
(boolean shrinkToFit) Controls if the Cell should be auto-sized to shrink to fit if the text is too longvoid
setTopBorderColor
(short color) set the color to use for the top bordervoid
setUserStyleName
(String styleName) Sets the name of the user defined style.void
set the type of vertical alignment for the cellvoid
setWrapText
(boolean wrapped) set whether the text should be wrappedvoid
Verifies that this style belongs to the supplied Workbook.
-
Constructor Details
-
HSSFCellStyle
Creates new HSSFCellStyle why would you want to do this?? -
HSSFCellStyle
-
-
Method Details
-
getIndex
public short getIndex()get the index within the HSSFWorkbook (sequence within the collection of ExtnededFormat objects) -
getParentStyle
Return the parent style for this cell style. In most cases this will be null, but in a few cases there'll be a fully defined parent. -
setDataFormat
public void setDataFormat(short fmt) set the data format (must be a valid format)- Specified by:
setDataFormat
in interfaceCellStyle
- See Also:
-
getDataFormat
public short getDataFormat()get the index of the format- Specified by:
getDataFormat
in interfaceCellStyle
- See Also:
-
getDataFormatString
Get the contents of the format string, by looking up the DataFormat against the bound workbook- Specified by:
getDataFormatString
in interfaceCellStyle
- Returns:
- the format string or "General" if not found
- See Also:
-
getDataFormatString
Get the contents of the format string, by looking up the DataFormat against the supplied workbook- Returns:
- the format string or "General" if not found
- See Also:
-
getDataFormatString
Get the contents of the format string, by looking up the DataFormat against the supplied low level workbook- See Also:
-
setFont
set the font for this style -
setFont
-
getFontIndex
Deprecated.gets the index of the font for this style- Specified by:
getFontIndex
in interfaceCellStyle
- See Also:
-
getFontIndexAsInt
public int getFontIndexAsInt()gets the index of the font for this style- Specified by:
getFontIndexAsInt
in interfaceCellStyle
- Since:
- 4.0.0
- See Also:
-
getFont
gets the font for this style- Parameters:
parentWorkbook
- The HSSFWorkbook that this style belongs to- See Also:
-
setHidden
public void setHidden(boolean hidden) set the cell's using this style to be hidden -
getHidden
public boolean getHidden()get whether the cell's using this style are to be hidden -
setLocked
public void setLocked(boolean locked) set the cell's using this style to be locked -
getLocked
public boolean getLocked()get whether the cell's using this style are 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:
setQuotePrefixed
in interfaceCellStyle
-
getQuotePrefixed
public boolean getQuotePrefixed()Is "Quote Prefix" or "123 Prefix" enabled for the cell?- Specified by:
getQuotePrefixed
in interfaceCellStyle
-
setAlignment
set the type of horizontal alignment for the cell- Specified by:
setAlignment
in interfaceCellStyle
- Parameters:
align
- - the type of alignment
-
getAlignment
Description copied from interface:CellStyle
get the type of horizontal alignment for the cell- Specified by:
getAlignment
in interfaceCellStyle
- Returns:
- align - the type of alignment
-
getAlignmentEnum
Description copied from interface:CellStyle
get the type of horizontal alignment for the cell- Specified by:
getAlignmentEnum
in interfaceCellStyle
- Returns:
- align - the type of alignment
-
setWrapText
public void setWrapText(boolean wrapped) set whether the text should be wrapped- Specified by:
setWrapText
in interfaceCellStyle
- Parameters:
wrapped
- wrap text or not
-
getWrapText
public boolean getWrapText()get whether the text should be wrapped- Specified by:
getWrapText
in interfaceCellStyle
- Returns:
- wrap text or not
-
setVerticalAlignment
set the type of vertical alignment for the cell- Specified by:
setVerticalAlignment
in interfaceCellStyle
- Parameters:
align
- the type of alignment
-
getVerticalAlignment
Description copied from interface:CellStyle
get the type of vertical alignment for the cell- Specified by:
getVerticalAlignment
in interfaceCellStyle
- Returns:
- align the type of alignment
-
getVerticalAlignmentEnum
Description copied from interface:CellStyle
get the type of vertical alignment for the cell- Specified by:
getVerticalAlignmentEnum
in interfaceCellStyle
- Returns:
- align the type of alignment
-
setRotation
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.- Specified by:
setRotation
in interfaceCellStyle
- Parameters:
rotation
- degrees (between -90 and 90 degrees, of 0xff for vertical)
-
getRotation
public short getRotation()get the degree of rotation for the text in the cell- Specified by:
getRotation
in interfaceCellStyle
- Returns:
- rotation degrees (between -90 and 90 degrees, or 0xff for vertical)
-
setIndention
public void setIndention(short indent) set the number of spaces to indent the text in the cell- Specified by:
setIndention
in interfaceCellStyle
- Parameters:
indent
- - number of spaces
-
getIndention
public short getIndention()get the number of spaces to indent the text in the cell- Specified by:
getIndention
in interfaceCellStyle
- Returns:
- indent - number of spaces
-
setBorderLeft
set the type of border to use for the left border of the cell- Specified by:
setBorderLeft
in interfaceCellStyle
- Parameters:
border
- type- Since:
- POI 3.15
-
getBorderLeft
Description copied from interface:CellStyle
get the type of border to use for the left border of the cell- Specified by:
getBorderLeft
in interfaceCellStyle
- Returns:
- border type
-
getBorderLeftEnum
Description copied from interface:CellStyle
get the type of border to use for the left border of the cell- Specified by:
getBorderLeftEnum
in interfaceCellStyle
- Returns:
- border type
-
setBorderRight
set the type of border to use for the right border of the cell- Specified by:
setBorderRight
in interfaceCellStyle
- Parameters:
border
- type- Since:
- POI 3.15
-
getBorderRight
Description copied from interface:CellStyle
get the type of border to use for the right border of the cell- Specified by:
getBorderRight
in interfaceCellStyle
- Returns:
- border type
-
getBorderRightEnum
Description copied from interface:CellStyle
get the type of border to use for the right border of the cell- Specified by:
getBorderRightEnum
in interfaceCellStyle
- Returns:
- border type
-
setBorderTop
set the type of border to use for the top border of the cell- Specified by:
setBorderTop
in interfaceCellStyle
- Parameters:
border
- type- Since:
- POI 3.15
-
getBorderTop
Description copied from interface:CellStyle
get the type of border to use for the top border of the cell- Specified by:
getBorderTop
in interfaceCellStyle
- Returns:
- border type
-
getBorderTopEnum
Description copied from interface:CellStyle
get the type of border to use for the top border of the cell- Specified by:
getBorderTopEnum
in interfaceCellStyle
- Returns:
- border type
-
setBorderBottom
set the type of border to use for the bottom border of the cell- Specified by:
setBorderBottom
in interfaceCellStyle
- Parameters:
border
- type- Since:
- 3.15 beta 2
-
getBorderBottom
Description copied from interface:CellStyle
get the type of border to use for the bottom border of the cell- Specified by:
getBorderBottom
in interfaceCellStyle
- Returns:
- border type
-
getBorderBottomEnum
Description copied from interface:CellStyle
get the type of border to use for the bottom border of the cell- Specified by:
getBorderBottomEnum
in interfaceCellStyle
- Returns:
- border type
-
setLeftBorderColor
public void setLeftBorderColor(short color) set the color to use for the left border- Specified by:
setLeftBorderColor
in interfaceCellStyle
- Parameters:
color
- The index of the color definition
-
getLeftBorderColor
public short getLeftBorderColor()get the color to use for the left border- Specified by:
getLeftBorderColor
in interfaceCellStyle
- Returns:
- The index of the color definition
- See Also:
-
setRightBorderColor
public void setRightBorderColor(short color) set the color to use for the right border- Specified by:
setRightBorderColor
in interfaceCellStyle
- Parameters:
color
- The index of the color definition
-
getRightBorderColor
public short getRightBorderColor()get the color to use for the left border- Specified by:
getRightBorderColor
in interfaceCellStyle
- Returns:
- The index of the color definition
- See Also:
-
setTopBorderColor
public void setTopBorderColor(short color) set the color to use for the top border- Specified by:
setTopBorderColor
in interfaceCellStyle
- Parameters:
color
- The index of the color definition
-
getTopBorderColor
public short getTopBorderColor()get the color to use for the top border- Specified by:
getTopBorderColor
in interfaceCellStyle
- Returns:
- The index of the color definition
- See Also:
-
setBottomBorderColor
public void setBottomBorderColor(short color) set the color to use for the bottom border- Specified by:
setBottomBorderColor
in interfaceCellStyle
- Parameters:
color
- The index of the color definition
-
getBottomBorderColor
public short getBottomBorderColor()get the color to use for the left border- Specified by:
getBottomBorderColor
in interfaceCellStyle
- Returns:
- The index of the color definition
- See Also:
-
setFillPattern
setting to one fills the cell with the foreground color... No idea about other values- Specified by:
setFillPattern
in interfaceCellStyle
- Parameters:
fp
- fill pattern (set toFillPatternType.SOLID_FOREGROUND
to fill w/foreground color)
-
getFillPattern
Description copied from interface:CellStyle
Get the fill pattern- Specified by:
getFillPattern
in interfaceCellStyle
- Returns:
- the fill pattern, default value is
FillPatternType.NO_FILL
-
getFillPatternEnum
Description copied from interface:CellStyle
Get the fill pattern- Specified by:
getFillPatternEnum
in interfaceCellStyle
- Returns:
- the fill pattern, default value is
FillPatternType.NO_FILL
-
setFillBackgroundColor
public void setFillBackgroundColor(short bg) set the background fill color.For example:
cs.setFillPattern(HSSFCellStyle.FINE_DOTS ); cs.setFillBackgroundColor(new HSSFColor.RED().getIndex());
optionally a Foreground and background fill can be applied: Note: Ensure Foreground color is set prior to backgroundcs.setFillPattern(HSSFCellStyle.FINE_DOTS ); cs.setFillForegroundColor(new HSSFColor.BLUE().getIndex()); cs.setFillBackgroundColor(new HSSFColor.RED().getIndex());
or, for the special case of SOLID_FILL:cs.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND ); cs.setFillForegroundColor(new HSSFColor.RED().getIndex());
It is necessary to set the fill style in order for the color to be shown in the cell.- Specified by:
setFillBackgroundColor
in interfaceCellStyle
- Parameters:
bg
- color
-
getFillBackgroundColor
public short getFillBackgroundColor()Get the background fill color. Note - many cells are actually filled with a foreground fill, not a background fill - seegetFillForegroundColor()
- Specified by:
getFillBackgroundColor
in interfaceCellStyle
- Returns:
- fill color
- See Also:
-
getFillBackgroundColorColor
Description copied from interface:CellStyle
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.- Specified by:
getFillBackgroundColorColor
in interfaceCellStyle
-
setFillForegroundColor
public void setFillForegroundColor(short bg) set the foreground fill color Note: Ensure Foreground color is set prior to background color.- Specified by:
setFillForegroundColor
in interfaceCellStyle
- Parameters:
bg
- color
-
getFillForegroundColor
public short getFillForegroundColor()Get the foreground fill color. Many cells are filled with this, instead of a background color (getFillBackgroundColor()
)- Specified by:
getFillForegroundColor
in interfaceCellStyle
- Returns:
- fill color
- See Also:
-
getFillForegroundColorColor
Description copied from interface:CellStyle
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.- Specified by:
getFillForegroundColorColor
in interfaceCellStyle
-
getUserStyleName
Gets the name of the user defined style. Returns null for built in styles, and styles where no name has been defined -
setUserStyleName
Sets the name of the user defined style. Will complain if you try this on a built in style. -
setShrinkToFit
public void setShrinkToFit(boolean shrinkToFit) Controls if the Cell should be auto-sized to shrink to fit if the text is too long- Specified by:
setShrinkToFit
in interfaceCellStyle
-
getShrinkToFit
public boolean getShrinkToFit()Should the Cell be auto-sized by Excel to shrink it to fit if this text is too long?- Specified by:
getShrinkToFit
in interfaceCellStyle
-
getReadingOrder
public short getReadingOrder()Get the reading order, for RTL/LTR ordering of the text.0 means Context (Default), 1 means Left To Right, and 2 means Right to Left
- Returns:
- order - the reading order (0,1,2)
-
setReadingOrder
public void setReadingOrder(short order) Sets the reading order, for RTL/LTR ordering of the text.0 means Context (Default), 1 means Left To Right, and 2 means Right to Left
- Parameters:
order
- - the reading order (0,1,2)
-
verifyBelongsToWorkbook
Verifies that this style belongs to the supplied Workbook. 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 HSSFCellStyle, onto this one. This HSSFCellStyle will then have all the same properties as the source, but the two may be edited independently. Any stylings on this HSSFCellStyle will be lost! The source HSSFCellStyle could be from another HSSFWorkbook if you like. This allows you to copy styles from one HSSFWorkbook to another.- Specified by:
cloneStyleFrom
in interfaceCellStyle
-
cloneStyleFrom
-
hashCode
public int hashCode() -
equals
-