FileDocCategorySizeDatePackage
HSSFCellStyle.javaAPI DocApache Poi 3.0.123560Mon Jan 01 12:39:36 GMT 2007org.apache.poi.hssf.usermodel

HSSFCellStyle

public class HSSFCellStyle extends Object
High level representation of the style of a cell in a sheet of a workbook.
version
1.0-pre
author
Andrew C. Oliver (acoliver at apache dot org)
author
Jason Height (jheight at chariot dot net dot au)
see
org.apache.poi.hssf.usermodel.HSSFWorkbook#createCellStyle()
see
org.apache.poi.hssf.usermodel.HSSFWorkbook#getCellStyleAt(short)
see
org.apache.poi.hssf.usermodel.HSSFCell#setCellStyle(HSSFCellStyle)

Fields Summary
private ExtendedFormatRecord
format
private short
index
public static final short
ALIGN_GENERAL
general (normal) horizontal alignment
public static final short
ALIGN_LEFT
left-justified horizontal alignment
public static final short
ALIGN_CENTER
center horizontal alignment
public static final short
ALIGN_RIGHT
right-justified horizontal alignment
public static final short
ALIGN_FILL
fill? horizontal alignment
public static final short
ALIGN_JUSTIFY
justified horizontal alignment
public static final short
ALIGN_CENTER_SELECTION
center-selection? horizontal alignment
public static final short
VERTICAL_TOP
top-aligned vertical alignment
public static final short
VERTICAL_CENTER
center-aligned vertical alignment
public static final short
VERTICAL_BOTTOM
bottom-aligned vertical alignment
public static final short
VERTICAL_JUSTIFY
vertically justified vertical alignment
public static final short
BORDER_NONE
No border
public static final short
BORDER_THIN
Thin border
public static final short
BORDER_MEDIUM
Medium border
public static final short
BORDER_DASHED
dash border
public static final short
BORDER_HAIR
dot border
public static final short
BORDER_THICK
Thick border
public static final short
BORDER_DOUBLE
double-line border
public static final short
BORDER_DOTTED
hair-line border
public static final short
BORDER_MEDIUM_DASHED
Medium dashed border
public static final short
BORDER_DASH_DOT
dash-dot border
public static final short
BORDER_MEDIUM_DASH_DOT
medium dash-dot border
public static final short
BORDER_DASH_DOT_DOT
dash-dot-dot border
public static final short
BORDER_MEDIUM_DASH_DOT_DOT
medium dash-dot-dot border
public static final short
BORDER_SLANTED_DASH_DOT
slanted dash-dot border
public static final short
NO_FILL
No background
public static final short
SOLID_FOREGROUND
Solidly filled
public static final short
FINE_DOTS
Small fine dots
public static final short
ALT_BARS
Wide dots
public static final short
SPARSE_DOTS
Sparse dots
public static final short
THICK_HORZ_BANDS
Thick horizontal bands
public static final short
THICK_VERT_BANDS
Thick vertical bands
public static final short
THICK_BACKWARD_DIAG
Thick backward facing diagonals
public static final short
THICK_FORWARD_DIAG
Thick forward facing diagonals
public static final short
BIG_SPOTS
Large spots
public static final short
BRICKS
Brick-like layout
public static final short
THIN_HORZ_BANDS
Thin horizontal bands
public static final short
THIN_VERT_BANDS
Thin vertical bands
public static final short
THIN_BACKWARD_DIAG
Thin backward diagonal
public static final short
THIN_FORWARD_DIAG
Thin forward diagonal
public static final short
SQUARES
Squares
public static final short
DIAMONDS
Diamonds
public static final short
LESS_DOTS
Less Dots
public static final short
LEAST_DOTS
Least Dots
Constructors Summary
protected HSSFCellStyle(short index, ExtendedFormatRecord rec)
Creates new HSSFCellStyle why would you want to do this??



               

        
    
        this.index = index;
        format     = rec;
    
Methods Summary
private voidcheckDefaultBackgroundFills()
Checks if the background and foreground fills are set correctly when one or the other is set to the default color.

Works like the logic table below:

BACKGROUND FOREGROUND

NONE AUTOMATIC

0x41 0x40

NONE RED/ANYTHING

0x40 0xSOMETHING

      if (format.getFillForeground() == org.apache.poi.hssf.util.HSSFColor.AUTOMATIC.index) {
    	  //JMH: Why +1, hell why not. I guess it made some sense to someone at the time. Doesnt
    	  //to me now.... But experience has shown that when the fore is set to AUTOMATIC then the
    	  //background needs to be incremented......
    	  if (format.getFillBackground() != (org.apache.poi.hssf.util.HSSFColor.AUTOMATIC.index+1))
    		  setFillBackgroundColor((short)(org.apache.poi.hssf.util.HSSFColor.AUTOMATIC.index+1));
      } else if (format.getFillBackground() == org.apache.poi.hssf.util.HSSFColor.AUTOMATIC.index+1)
    	  //Now if the forground changes to a non-AUTOMATIC color the background resets itself!!!
    	  if (format.getFillForeground() != org.apache.poi.hssf.util.HSSFColor.AUTOMATIC.index)
    		  setFillBackgroundColor(org.apache.poi.hssf.util.HSSFColor.AUTOMATIC.index);
    
public shortgetAlignment()
get the type of horizontal alignment for the cell

return
align - the type of alignment
see
#ALIGN_GENERAL
see
#ALIGN_LEFT
see
#ALIGN_CENTER
see
#ALIGN_RIGHT
see
#ALIGN_FILL
see
#ALIGN_JUSTIFY
see
#ALIGN_CENTER_SELECTION

        return format.getAlignment();
    
public shortgetBorderBottom()
get the type of border to use for the bottom border of the cell

return
border type
see
#BORDER_NONE
see
#BORDER_THIN
see
#BORDER_MEDIUM
see
#BORDER_DASHED
see
#BORDER_DOTTED
see
#BORDER_THICK
see
#BORDER_DOUBLE
see
#BORDER_HAIR
see
#BORDER_MEDIUM_DASHED
see
#BORDER_DASH_DOT
see
#BORDER_MEDIUM_DASH_DOT
see
#BORDER_DASH_DOT_DOT
see
#BORDER_MEDIUM_DASH_DOT_DOT
see
#BORDER_SLANTED_DASH_DOT

        return format.getBorderBottom();
    
public shortgetBorderLeft()
get the type of border to use for the left border of the cell

return
border type
see
#BORDER_NONE
see
#BORDER_THIN
see
#BORDER_MEDIUM
see
#BORDER_DASHED
see
#BORDER_DOTTED
see
#BORDER_THICK
see
#BORDER_DOUBLE
see
#BORDER_HAIR
see
#BORDER_MEDIUM_DASHED
see
#BORDER_DASH_DOT
see
#BORDER_MEDIUM_DASH_DOT
see
#BORDER_DASH_DOT_DOT
see
#BORDER_MEDIUM_DASH_DOT_DOT
see
#BORDER_SLANTED_DASH_DOT

        return format.getBorderLeft();
    
public shortgetBorderRight()
get the type of border to use for the right border of the cell

return
border type
see
#BORDER_NONE
see
#BORDER_THIN
see
#BORDER_MEDIUM
see
#BORDER_DASHED
see
#BORDER_DOTTED
see
#BORDER_THICK
see
#BORDER_DOUBLE
see
#BORDER_HAIR
see
#BORDER_MEDIUM_DASHED
see
#BORDER_DASH_DOT
see
#BORDER_MEDIUM_DASH_DOT
see
#BORDER_DASH_DOT_DOT
see
#BORDER_MEDIUM_DASH_DOT_DOT
see
#BORDER_SLANTED_DASH_DOT

        return format.getBorderRight();
    
public shortgetBorderTop()
get the type of border to use for the top border of the cell

return
border type
see
#BORDER_NONE
see
#BORDER_THIN
see
#BORDER_MEDIUM
see
#BORDER_DASHED
see
#BORDER_DOTTED
see
#BORDER_THICK
see
#BORDER_DOUBLE
see
#BORDER_HAIR
see
#BORDER_MEDIUM_DASHED
see
#BORDER_DASH_DOT
see
#BORDER_MEDIUM_DASH_DOT
see
#BORDER_DASH_DOT_DOT
see
#BORDER_MEDIUM_DASH_DOT_DOT
see
#BORDER_SLANTED_DASH_DOT

        return format.getBorderTop();
    
public shortgetBottomBorderColor()
get the color to use for the left border

return
color

        return format.getBottomBorderPaletteIdx();
    
public shortgetDataFormat()
get the index of the format

see
org.apache.poi.hssf.usermodel.HSSFDataFormat

        return format.getFormatIndex();
    
public shortgetFillBackgroundColor()
get the background fill color

return
fill color

    	short result = format.getFillBackground();
    	//JMH: Do this ridiculous conversion, and let HSSFCellStyle
    	//internally migrate back and forth
    	if (result == (HSSFColor.AUTOMATIC.index+1))
    		return HSSFColor.AUTOMATIC.index;
    	else return result;
    
public shortgetFillForegroundColor()
get the foreground fill color

return
fill color

        return format.getFillForeground();
    
public shortgetFillPattern()
get the fill pattern (??) - set to 1 to fill with foreground color

return
fill pattern

        return format.getAdtlFillPattern();
    
public shortgetFontIndex()

        return format.getFontIndex();
    
public booleangetHidden()
get whether the cell's using this style are to be hidden

return
hidden - whether the cell using this style should be hidden

        return format.isHidden();
    
public shortgetIndention()
get the number of spaces to indent the text in the cell

return
indent - number of spaces

        return format.getIndent();
    
public shortgetIndex()
get the index within the HSSFWorkbook (sequence within the collection of ExtnededFormat objects)

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

        return index;
    
public shortgetLeftBorderColor()
get the color to use for the left border

return
color

        return format.getLeftBorderPaletteIdx();
    
public booleangetLocked()
get whether the cell's using this style are to be locked

return
hidden - whether the cell using this style should be locked

        return format.isLocked();
    
public shortgetRightBorderColor()
get the color to use for the left border

return
color

        return format.getRightBorderPaletteIdx();
    
public shortgetRotation()
get the degree of rotation for the text in the cell

return
rotation degrees (between -90 and 90 degrees)

      short rotation = format.getRotation();
      if (rotation > 90)
        //This is actually the 4th quadrant
        rotation = (short)(90-rotation);
      return rotation;
    
public shortgetTopBorderColor()
get the color to use for the top border

return
color

        return format.getTopBorderPaletteIdx();
    
public shortgetVerticalAlignment()
get the type of vertical alignment for the cell

return
align the type of alignment
see
#VERTICAL_TOP
see
#VERTICAL_CENTER
see
#VERTICAL_BOTTOM
see
#VERTICAL_JUSTIFY

        return format.getVerticalAlignment();
    
public booleangetWrapText()
get whether the text should be wrapped

return
wrap text or not

        return format.getWrapText();
    
public voidsetAlignment(short align)
set the type of horizontal alignment for the cell

param
align - the type of alignment
see
#ALIGN_GENERAL
see
#ALIGN_LEFT
see
#ALIGN_CENTER
see
#ALIGN_RIGHT
see
#ALIGN_FILL
see
#ALIGN_JUSTIFY
see
#ALIGN_CENTER_SELECTION

        format.setIndentNotParentAlignment(true);
        format.setAlignment(align);
    
public voidsetBorderBottom(short border)
set the type of border to use for the bottom border of the cell

param
border type
see
#BORDER_NONE
see
#BORDER_THIN
see
#BORDER_MEDIUM
see
#BORDER_DASHED
see
#BORDER_DOTTED
see
#BORDER_THICK
see
#BORDER_DOUBLE
see
#BORDER_HAIR
see
#BORDER_MEDIUM_DASHED
see
#BORDER_DASH_DOT
see
#BORDER_MEDIUM_DASH_DOT
see
#BORDER_DASH_DOT_DOT
see
#BORDER_MEDIUM_DASH_DOT_DOT
see
#BORDER_SLANTED_DASH_DOT

        format.setIndentNotParentBorder(true);
        format.setBorderBottom(border);
    
public voidsetBorderLeft(short border)
set the type of border to use for the left border of the cell

param
border type
see
#BORDER_NONE
see
#BORDER_THIN
see
#BORDER_MEDIUM
see
#BORDER_DASHED
see
#BORDER_DOTTED
see
#BORDER_THICK
see
#BORDER_DOUBLE
see
#BORDER_HAIR
see
#BORDER_MEDIUM_DASHED
see
#BORDER_DASH_DOT
see
#BORDER_MEDIUM_DASH_DOT
see
#BORDER_DASH_DOT_DOT
see
#BORDER_MEDIUM_DASH_DOT_DOT
see
#BORDER_SLANTED_DASH_DOT

        format.setIndentNotParentBorder(true);
        format.setBorderLeft(border);
    
public voidsetBorderRight(short border)
set the type of border to use for the right border of the cell

param
border type
see
#BORDER_NONE
see
#BORDER_THIN
see
#BORDER_MEDIUM
see
#BORDER_DASHED
see
#BORDER_DOTTED
see
#BORDER_THICK
see
#BORDER_DOUBLE
see
#BORDER_HAIR
see
#BORDER_MEDIUM_DASHED
see
#BORDER_DASH_DOT
see
#BORDER_MEDIUM_DASH_DOT
see
#BORDER_DASH_DOT_DOT
see
#BORDER_MEDIUM_DASH_DOT_DOT
see
#BORDER_SLANTED_DASH_DOT

        format.setIndentNotParentBorder(true);
        format.setBorderRight(border);
    
public voidsetBorderTop(short border)
set the type of border to use for the top border of the cell

param
border type
see
#BORDER_NONE
see
#BORDER_THIN
see
#BORDER_MEDIUM
see
#BORDER_DASHED
see
#BORDER_DOTTED
see
#BORDER_THICK
see
#BORDER_DOUBLE
see
#BORDER_HAIR
see
#BORDER_MEDIUM_DASHED
see
#BORDER_DASH_DOT
see
#BORDER_MEDIUM_DASH_DOT
see
#BORDER_DASH_DOT_DOT
see
#BORDER_MEDIUM_DASH_DOT_DOT
see
#BORDER_SLANTED_DASH_DOT

        format.setIndentNotParentBorder(true);
        format.setBorderTop(border);
    
public voidsetBottomBorderColor(short color)
set the color to use for the bottom border

param
color

        format.setBottomBorderPaletteIdx(color);
    
public voidsetDataFormat(short fmt)
set the data format (must be a valid format)

see
org.apache.poi.hssf.usermodel.HSSFDataFormat

        format.setFormatIndex(fmt);
    
public voidsetFillBackgroundColor(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 background
cs.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.

param
bg color

    	
        format.setFillBackground(bg);
        checkDefaultBackgroundFills();
    
public voidsetFillForegroundColor(short bg)
set the foreground fill color Note: Ensure Foreground color is set prior to background color.

param
bg color

        format.setFillForeground(bg);
        checkDefaultBackgroundFills();
    
public voidsetFillPattern(short fp)
setting to one fills the cell with the foreground color... No idea about other values

see
#NO_FILL
see
#SOLID_FOREGROUND
see
#FINE_DOTS
see
#ALT_BARS
see
#SPARSE_DOTS
see
#THICK_HORZ_BANDS
see
#THICK_VERT_BANDS
see
#THICK_BACKWARD_DIAG
see
#THICK_FORWARD_DIAG
see
#BIG_SPOTS
see
#BRICKS
see
#THIN_HORZ_BANDS
see
#THIN_VERT_BANDS
see
#THIN_BACKWARD_DIAG
see
#THIN_FORWARD_DIAG
see
#SQUARES
see
#DIAMONDS
param
fp fill pattern (set to 1 to fill w/foreground color)

        format.setAdtlFillPattern(fp);
    
public voidsetFont(org.apache.poi.hssf.usermodel.HSSFFont font)
set the font for this style

param
font a font object created or retreived from the HSSFWorkbook object
see
org.apache.poi.hssf.usermodel.HSSFWorkbook#createFont()
see
org.apache.poi.hssf.usermodel.HSSFWorkbook#getFontAt(short)

        format.setIndentNotParentFont(true);
        short fontindex = font.getIndex();
        format.setFontIndex(fontindex);
    
public voidsetHidden(boolean hidden)
set the cell's using this style to be hidden

param
hidden - whether the cell using this style should be hidden

        format.setIndentNotParentCellOptions(true);
        format.setHidden(hidden);
    
public voidsetIndention(short indent)
set the number of spaces to indent the text in the cell

param
indent - number of spaces

        format.setIndent(indent);
    
public voidsetLeftBorderColor(short color)
set the color to use for the left border

param
color

        format.setLeftBorderPaletteIdx(color);
    
public voidsetLocked(boolean locked)
set the cell's using this style to be locked

param
locked - whether the cell using this style should be locked

        format.setIndentNotParentCellOptions(true);
        format.setLocked(locked);
    
public voidsetRightBorderColor(short color)
set the color to use for the right border

param
color

        format.setRightBorderPaletteIdx(color);
    
public voidsetRotation(short rotation)
set the degree of rotation for the text in the cell

param
rotation degrees (between -90 and 90 degrees)

      if ((rotation < 0)&&(rotation >= -90)) {
        //Take care of the funny 4th quadrant issue
        //The 4th quadrant (-1 to -90) is stored as (91 to 180)
        rotation = (short)(90 - rotation);
      }
      else if ((rotation < -90)  ||(rotation > 90))
        //Do not allow an incorrect rotation to be set
        throw new IllegalArgumentException("The rotation must be between -90 and 90 degrees");
        format.setRotation(rotation);
    
public voidsetTopBorderColor(short color)
set the color to use for the top border

param
color

        format.setTopBorderPaletteIdx(color);
    
public voidsetVerticalAlignment(short align)
set the type of vertical alignment for the cell

param
align the type of alignment
see
#VERTICAL_TOP
see
#VERTICAL_CENTER
see
#VERTICAL_BOTTOM
see
#VERTICAL_JUSTIFY

        format.setVerticalAlignment(align);
    
public voidsetWrapText(boolean wrapped)
set whether the text should be wrapped

param
wrapped wrap text or not

        format.setIndentNotParentAlignment(true);
        format.setWrapText(wrapped);