Package org.apache.poi.hssf.usermodel
Class HSSFCellStyle
- java.lang.Object
-
- org.apache.poi.hssf.usermodel.HSSFCellStyle
-
- All Implemented Interfaces:
Duplicatable,CellStyle
public final class HSSFCellStyle extends Object implements CellStyle, Duplicatable
High level representation of the style of a cell in a sheet of a workbook.
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedHSSFCellStyle(short index, ExtendedFormatRecord rec, InternalWorkbook workbook)protectedHSSFCellStyle(short index, ExtendedFormatRecord rec, HSSFWorkbook workbook)Creates new HSSFCellStyle why would you want to do this??protectedHSSFCellStyle(HSSFCellStyle other)
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidcloneStyleFrom(HSSFCellStyle source)voidcloneStyleFrom(CellStyle source)Clones all the style information from another HSSFCellStyle, onto this one.HSSFCellStylecopy()booleanequals(Object obj)HorizontalAlignmentgetAlignment()get the type of horizontal alignment for the cellBorderStylegetBorderBottom()get the type of border to use for the bottom border of the cellBorderStylegetBorderLeft()get the type of border to use for the left border of the cellBorderStylegetBorderRight()get the type of border to use for the right border of the cellBorderStylegetBorderTop()get the type of border to use for the top border of the cellshortgetBottomBorderColor()get the color to use for the left bordershortgetDataFormat()get the index of the formatStringgetDataFormatString()Get the contents of the format string, by looking up the DataFormat against the bound workbookStringgetDataFormatString(InternalWorkbook workbook)Get the contents of the format string, by looking up the DataFormat against the supplied low level workbookStringgetDataFormatString(Workbook workbook)Get the contents of the format string, by looking up the DataFormat against the supplied workbookshortgetFillBackgroundColor()Get the background fill color.HSSFColorgetFillBackgroundColorColor()Gets the color object representing the current background fill, resolving indexes using the supplied workbook.shortgetFillForegroundColor()Get the foreground fill color.HSSFColorgetFillForegroundColorColor()Gets the color object representing the current foreground fill, resolving indexes using the supplied workbook.FillPatternTypegetFillPattern()Get the fill patternHSSFFontgetFont(Workbook parentWorkbook)gets the font for this styleintgetFontIndex()gets the index of the font for this styleintgetFontIndexAsInt()Deprecated.usegetFontIndex()insteadbooleangetHidden()get whether the cell's using this style are to be hiddenshortgetIndention()get the number of spaces to indent the text in the cellshortgetIndex()get the index within the HSSFWorkbook (sequence within the collection of ExtendedFormat objects)shortgetLeftBorderColor()get the color to use for the left borderbooleangetLocked()get whether the cell's using this style are to be lockedHSSFCellStylegetParentStyle()Return the parent style for this cell style.booleangetQuotePrefixed()Is "Quote Prefix" or "123 Prefix" enabled for the cell?shortgetReadingOrder()Get the reading order, for RTL/LTR ordering of the text.shortgetRightBorderColor()get the color to use for the left bordershortgetRotation()get the degree of rotation for the text in the cellbooleangetShrinkToFit()Should the Cell be auto-sized by Excel to shrink it to fit if this text is too long?shortgetTopBorderColor()get the color to use for the top borderStringgetUserStyleName()Gets the name of the user defined style.VerticalAlignmentgetVerticalAlignment()get the type of vertical alignment for the cellbooleangetWrapText()get whether the text should be wrappedinthashCode()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 cellvoidsetBorderLeft(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(HSSFColor color)voidsetDataFormat(short fmt)set the data format (must be a valid format)voidsetFillBackgroundColor(short bg)set the background fill color.voidsetFillBackgroundColor(Color color)Set the background fill color represented as aColorvalue.voidsetFillForegroundColor(short bg)set the foreground fill color Note: Ensure Foreground color is set prior to background color.voidsetFillForegroundColor(Color color)Set the foreground fill color represented as aColorvalue.voidsetFillPattern(FillPatternType fp)setting to one fills the cell with the foreground color...voidsetFont(HSSFFont font)voidsetFont(Font font)set the font for this stylevoidsetFontColorColor(Color color)voidsetHidden(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 bordervoidsetLeftBorderColor(HSSFColor color)voidsetLocked(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(short order)Sets the reading order, for RTL/LTR ordering of the text.voidsetRightBorderColor(short color)set the color to use for the right bordervoidsetRightBorderColor(HSSFColor color)voidsetRotation(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.voidsetShrinkToFit(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(HSSFColor color)voidsetUserStyleName(String styleName)Sets the name of the user defined style.voidsetVerticalAlignment(VerticalAlignment align)set the type of vertical alignment for the cellvoidsetWrapText(boolean wrapped)set whether the text should be wrappedvoidverifyBelongsToWorkbook(HSSFWorkbook wb)Verifies that this style belongs to the supplied Workbook.
-
-
-
Constructor Detail
-
HSSFCellStyle
protected HSSFCellStyle(short index, ExtendedFormatRecord rec, HSSFWorkbook workbook)Creates new HSSFCellStyle why would you want to do this??
-
HSSFCellStyle
protected HSSFCellStyle(short index, ExtendedFormatRecord rec, InternalWorkbook workbook)
-
HSSFCellStyle
protected HSSFCellStyle(HSSFCellStyle other)
-
-
Method Detail
-
getIndex
public short getIndex()
get the index within the HSSFWorkbook (sequence within the collection of ExtendedFormat objects)
-
getParentStyle
public HSSFCellStyle 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:
setDataFormatin interfaceCellStyle- See Also:
HSSFDataFormat
-
getDataFormat
public short getDataFormat()
get the index of the format- Specified by:
getDataFormatin interfaceCellStyle- See Also:
HSSFDataFormat
-
getDataFormatString
public String getDataFormatString()
Get the contents of the format string, by looking up the DataFormat against the bound workbook- Specified by:
getDataFormatStringin interfaceCellStyle- Returns:
- the format string or "General" if not found
- See Also:
HSSFDataFormat
-
getDataFormatString
public String getDataFormatString(Workbook workbook)
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:
HSSFDataFormat
-
getDataFormatString
public String getDataFormatString(InternalWorkbook workbook)
Get the contents of the format string, by looking up the DataFormat against the supplied low level workbook- See Also:
HSSFDataFormat
-
setFont
public void setFont(Font font)
set the font for this style- Specified by:
setFontin interfaceCellStyle- Parameters:
font- a font object created or retrieved from the HSSFWorkbook object- See Also:
HSSFWorkbook.createFont(),HSSFWorkbook.getFontAt(int)
-
setFont
public void setFont(HSSFFont font)
-
getFontIndex
public int getFontIndex()
gets the index of the font for this style- Specified by:
getFontIndexin interfaceCellStyle- Since:
- 5.0.0 (used to return a short value)
- See Also:
HSSFWorkbook.getFontAt(int)
-
getFontIndexAsInt
@Deprecated @Removal(version="6.0.0") public int getFontIndexAsInt()
Deprecated.usegetFontIndex()insteadgets the index of the font for this style- Specified by:
getFontIndexAsIntin interfaceCellStyle- Since:
- 4.0.0
- See Also:
HSSFWorkbook.getFontAt(int)
-
getFont
public HSSFFont getFont(Workbook parentWorkbook)
gets the font for this style- Parameters:
parentWorkbook- The HSSFWorkbook that this style belongs to- See Also:
getFontIndex(),HSSFWorkbook.getFontAt(int)
-
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:
setQuotePrefixedin interfaceCellStyle
-
getQuotePrefixed
public boolean getQuotePrefixed()
Is "Quote Prefix" or "123 Prefix" enabled for the cell?- Specified by:
getQuotePrefixedin interfaceCellStyle
-
setAlignment
public void setAlignment(HorizontalAlignment align)
set the type of horizontal alignment for the cell- Specified by:
setAlignmentin interfaceCellStyle- Parameters:
align- - the type of alignment
-
getAlignment
public HorizontalAlignment getAlignment()
Description copied from interface:CellStyleget the type of horizontal alignment for the cell- Specified by:
getAlignmentin interfaceCellStyle- Returns:
- align - the type of alignment
-
setWrapText
public void setWrapText(boolean wrapped)
set whether the text should be wrapped- Specified by:
setWrapTextin interfaceCellStyle- Parameters:
wrapped- wrap text or not
-
getWrapText
public boolean getWrapText()
get whether the text should be wrapped- Specified by:
getWrapTextin interfaceCellStyle- Returns:
- wrap text or not
-
setVerticalAlignment
public void setVerticalAlignment(VerticalAlignment align)
set the type of vertical alignment for the cell- Specified by:
setVerticalAlignmentin interfaceCellStyle- Parameters:
align- the type of alignment
-
getVerticalAlignment
public VerticalAlignment getVerticalAlignment()
Description copied from interface:CellStyleget the type of vertical alignment for the cell- Specified by:
getVerticalAlignmentin 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:
setRotationin 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:
getRotationin 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:
setIndentionin interfaceCellStyle- Parameters:
indent- - number of spaces
-
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
-
setBorderLeft
public void setBorderLeft(BorderStyle border)
set the type of border to use for the left border of the cell- Specified by:
setBorderLeftin interfaceCellStyle- Parameters:
border- type- Since:
- POI 3.15
-
getBorderLeft
public BorderStyle 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
-
setBorderRight
public void setBorderRight(BorderStyle border)
set the type of border to use for the right border of the cell- Specified by:
setBorderRightin interfaceCellStyle- Parameters:
border- type- Since:
- POI 3.15
-
getBorderRight
public BorderStyle 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
-
setBorderTop
public void setBorderTop(BorderStyle border)
set the type of border to use for the top border of the cell- Specified by:
setBorderTopin interfaceCellStyle- Parameters:
border- type- Since:
- POI 3.15
-
getBorderTop
public BorderStyle 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
-
setBorderBottom
public void setBorderBottom(BorderStyle border)
set the type of border to use for the bottom border of the cell- Specified by:
setBorderBottomin interfaceCellStyle- Parameters:
border- type- Since:
- 3.15 beta 2
-
getBorderBottom
public BorderStyle 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
-
setLeftBorderColor
public void setLeftBorderColor(short color)
set the color to use for the left border- Specified by:
setLeftBorderColorin interfaceCellStyle- Parameters:
color- The index of the color definition
-
getLeftBorderColor
public short getLeftBorderColor()
get the color to use for the left border- Specified by:
getLeftBorderColorin interfaceCellStyle- Returns:
- The index of the color definition
- See Also:
HSSFPalette.getColor(short)
-
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
-
getRightBorderColor
public short getRightBorderColor()
get the color to use for the left border- Specified by:
getRightBorderColorin interfaceCellStyle- Returns:
- The index of the color definition
- See Also:
HSSFPalette.getColor(short)
-
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
-
getTopBorderColor
public short getTopBorderColor()
get the color to use for the top border- Specified by:
getTopBorderColorin interfaceCellStyle- Returns:
- The index of the color definition
- See Also:
HSSFPalette.getColor(short)
-
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
-
getBottomBorderColor
public short getBottomBorderColor()
get the color to use for the left border- Specified by:
getBottomBorderColorin interfaceCellStyle- Returns:
- The index of the color definition
- See Also:
HSSFPalette.getColor(short)
-
setFillPattern
public void setFillPattern(FillPatternType fp)
setting to one fills the cell with the foreground color... No idea about other values- Specified by:
setFillPatternin interfaceCellStyle- Parameters:
fp- fill pattern (set toFillPatternType.SOLID_FOREGROUNDto fill w/foreground color)
-
getFillPattern
public FillPatternType getFillPattern()
Description copied from interface:CellStyleGet the fill pattern- Specified by:
getFillPatternin 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:
setFillBackgroundColorin interfaceCellStyle- Parameters:
bg- color
-
setFillBackgroundColor
public void setFillBackgroundColor(Color color)
Set the background fill color represented as aColorvalue.- Specified by:
setFillBackgroundColorin interfaceCellStyle- Parameters:
color- the color to use- Throws:
IllegalArgumentException- if you provide aColorinstance that is not aHSSFColor- Since:
- POI 5.2.3
-
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:
getFillBackgroundColorin interfaceCellStyle- Returns:
- fill color
- See Also:
HSSFPalette.getColor(short)
-
getFillBackgroundColorColor
public HSSFColor 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
-
setFillForegroundColor
public void setFillForegroundColor(short bg)
set the foreground fill color Note: Ensure Foreground color is set prior to background color.- Specified by:
setFillForegroundColorin interfaceCellStyle- Parameters:
bg- color
-
setFillForegroundColor
public void setFillForegroundColor(Color color)
Set the foreground fill color represented as aColorvalue.- Specified by:
setFillForegroundColorin interfaceCellStyle- Parameters:
color- the color to use- Throws:
IllegalArgumentException- if you provide aColorinstance that is not aHSSFColor- Since:
- POI 5.2.3
-
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
- See Also:
HSSFPalette.getColor(short)
-
getFillForegroundColorColor
public HSSFColor 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
-
getUserStyleName
public String getUserStyleName()
Gets the name of the user defined style. Returns null for built in styles, and styles where no name has been defined
-
setUserStyleName
public void setUserStyleName(String styleName)
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:
setShrinkToFitin 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:
getShrinkToFitin 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
public void verifyBelongsToWorkbook(HSSFWorkbook wb)
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
public void cloneStyleFrom(CellStyle source)
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:
cloneStyleFromin interfaceCellStyle
-
cloneStyleFrom
public void cloneStyleFrom(HSSFCellStyle source)
-
copy
public HSSFCellStyle copy()
- Specified by:
copyin interfaceDuplicatable- Returns:
- a deep copy of the implementing class / instance
-
setFontColorColor
public void setFontColorColor(Color color)
-
setTopBorderColor
public void setTopBorderColor(HSSFColor color)
-
setBottomBorderColor
public void setBottomBorderColor(HSSFColor color)
-
setRightBorderColor
public void setRightBorderColor(HSSFColor color)
-
setLeftBorderColor
public void setLeftBorderColor(HSSFColor color)
-
-