Class XSSFFont

java.lang.Object
org.apache.poi.xssf.usermodel.XSSFFont
All Implemented Interfaces:
Font

public class XSSFFont extends Object implements Font
Represents a font used in a workbook.
  • Field Details

    • DEFAULT_FONT_NAME

      public static final String DEFAULT_FONT_NAME
      By default, Microsoft Office Excel 2007 uses the Calibri font in font size 11
      See Also:
    • DEFAULT_FONT_SIZE

      public static final short DEFAULT_FONT_SIZE
      By default, Microsoft Office Excel 2007 uses the Calibri font in font size 11
      See Also:
    • DEFAULT_FONT_COLOR

      public static final short DEFAULT_FONT_COLOR
      Default font color is black
      See Also:
  • Constructor Details

    • XSSFFont

      @Internal public XSSFFont(CTFont font)
      Create a new XSSFFont
      Parameters:
      font - the underlying CTFont bean
    • XSSFFont

      @Internal public XSSFFont(CTFont font, int index, IndexedColorMap colorMap)
      Called from parsing styles.xml
      Parameters:
      font - CTFont
      index - font index
      colorMap - for default or custom indexed colors
    • XSSFFont

      public XSSFFont()
      Create a new XSSFont. This method is protected to be used only by XSSFWorkbook
  • Method Details

    • getCTFont

      @Internal public CTFont getCTFont()
      get the underlying CTFont font
    • getBold

      public boolean getBold()
      get a boolean value for the boldness to use.
      Specified by:
      getBold in interface Font
      Returns:
      boolean - bold
    • getCharSet

      public int getCharSet()
      get character-set to use.
      Specified by:
      getCharSet in interface Font
      Returns:
      int - character-set (0-255)
      See Also:
    • getColor

      public short getColor()
      get the indexed color value for the font References a color defined in IndexedColors.
      Specified by:
      getColor in interface Font
      Returns:
      short - indexed color to use
      See Also:
    • getXSSFColor

      public XSSFColor getXSSFColor()
      get the color value for the font References a color defined as Standard Alpha Red Green Blue color value (ARGB).
      Returns:
      XSSFColor - rgb color to use
    • getThemeColor

      public short getThemeColor()
      get the color value for the font References a color defined in theme.
      Returns:
      short - theme defined to use
    • getFontHeight

      public short getFontHeight()
      Get the font height in unit's of 1/20th of a point.

      For many users, the related getFontHeightInPoints() will be more helpful, as that returns font heights in the more familiar points units, eg 10, 12, 14.

      Specified by:
      getFontHeight in interface Font
      Returns:
      short - height in 1/20ths of a point
      See Also:
    • getFontHeightInPoints

      public short getFontHeightInPoints()
      Get the font height in points.

      This will return the same font height that is shown in Excel, such as 10 or 14 or 28.

      Specified by:
      getFontHeightInPoints in interface Font
      Returns:
      short - height in the familiar unit of measure - points
      See Also:
    • getFontName

      public String getFontName()
      get the name of the font (i.e. Arial)
      Specified by:
      getFontName in interface Font
      Returns:
      String - a string representing the name of the font to use
    • getItalic

      public boolean getItalic()
      get a boolean value that specify whether to use italics or not
      Specified by:
      getItalic in interface Font
      Returns:
      boolean - value for italic
    • getStrikeout

      public boolean getStrikeout()
      get a boolean value that specify whether to use a strikeout horizontal line through the text or not
      Specified by:
      getStrikeout in interface Font
      Returns:
      boolean - value for strikeout
    • getTypeOffset

      public short getTypeOffset()
      get normal,super or subscript.
      Specified by:
      getTypeOffset in interface Font
      Returns:
      short - offset type to use (none,super,sub)
      See Also:
    • getUnderline

      public byte getUnderline()
      get type of text underlining to use
      Specified by:
      getUnderline in interface Font
      Returns:
      byte - underlining type
      See Also:
    • setBold

      public void setBold(boolean bold)
      set a boolean value for the boldness to use. If omitted, the default value is true.
      Specified by:
      setBold in interface Font
      Parameters:
      bold - - boldness to use
    • setCharSet

      public void setCharSet(byte charset)
      set character-set to use.
      Specified by:
      setCharSet in interface Font
      Parameters:
      charset - - charset
      See Also:
    • setCharSet

      public void setCharSet(int charset)
      set character-set to use.
      Specified by:
      setCharSet in interface Font
      Parameters:
      charset - - charset
      See Also:
    • setCharSet

      @Deprecated @Removal(version="6.0.0") public void setCharSet(FontCharset charSet)
      Deprecated.
      set character-set to use.
    • setCharSet

      public void setCharSet(FontCharset charSet)
      set character-set to use.
      Since:
      5.0.0
    • setColor

      public void setColor(short color)
      set the indexed color for the font
      Specified by:
      setColor in interface Font
      Parameters:
      color - - color to use
      See Also:
    • setColor

      public void setColor(XSSFColor color)
      set the color for the font in Standard Alpha Red Green Blue color value
      Parameters:
      color - - color to use
    • setFontHeight

      public void setFontHeight(short height)
      set the font height in points.
      Specified by:
      setFontHeight in interface Font
      Parameters:
      height - - height in points
      See Also:
    • setFontHeight

      public void setFontHeight(double height)
      set the font height in points.
      Parameters:
      height - - height in points
    • setFontHeightInPoints

      public void setFontHeightInPoints(short height)
      set the font height in points.
      Specified by:
      setFontHeightInPoints in interface Font
      Parameters:
      height - height in the familiar unit of measure - points
      See Also:
    • setThemeColor

      public void setThemeColor(short theme)
      set the theme color for the font to use
      Parameters:
      theme - - theme color to use
    • setFontName

      public void setFontName(String name)
      set the name for the font (i.e. Arial). If the font doesn't exist (because it isn't installed on the system), or the charset is invalid for that font, then another font should be substituted. The string length for this attribute shall be 0 to 31 characters. Default font name is Calibri.
      Specified by:
      setFontName in interface Font
      Parameters:
      name - - value representing the name of the font to use
      See Also:
    • setItalic

      public void setItalic(boolean italic)
      set a boolean value for the property specifying whether to use italics or not If omitted, the default value is true.
      Specified by:
      setItalic in interface Font
      Parameters:
      italic - - value for italics or not
    • setStrikeout

      public void setStrikeout(boolean strikeout)
      set a boolean value for the property specifying whether to use a strikeout horizontal line through the text or not If omitted, the default value is true.
      Specified by:
      setStrikeout in interface Font
      Parameters:
      strikeout - - value for strikeout or not
    • setTypeOffset

      public void setTypeOffset(short offset)
      set normal,super or subscript, that representing the vertical-alignment setting. Setting this to either subscript or superscript shall make the font size smaller if a smaller font size is available.
      Specified by:
      setTypeOffset in interface Font
      Parameters:
      offset - - offset type to use (none,super,sub)
      See Also:
    • setUnderline

      public void setUnderline(byte underline)
      set the style of underlining that is used. The none style is equivalent to not using underlining at all.
      Specified by:
      setUnderline in interface Font
      Parameters:
      underline - - underline type to use
      See Also:
    • setUnderline

      public void setUnderline(FontUnderline underline)
      set an enumeration representing the style of underlining that is used. The none style is equivalent to not using underlining at all. The possible values for this attribute are defined by the FontUnderline
      Parameters:
      underline - - FontUnderline enum value
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • registerTo

      public long registerTo(StylesTable styles)
      Perform a registration of ourselves to the style table
    • registerTo

      public long registerTo(StylesTable styles, boolean force)
    • setThemesTable

      public void setThemesTable(ThemesTable themes)
      Records the Themes Table that is associated with the current font, used when looking up theme based colours and properties.
    • getScheme

      public FontScheme getScheme()
      get the font scheme property. is used only in StylesTable to create the default instance of font
      Returns:
      FontScheme
      See Also:
      • StylesTable.createDefaultFont()
    • setScheme

      public void setScheme(FontScheme scheme)
      set font scheme property
      Parameters:
      scheme - - FontScheme enum value
      See Also:
    • getFamily

      public int getFamily()
      get the font family to use.
      Returns:
      the font family to use
      See Also:
    • setFamily

      public void setFamily(int value)
      Set the font family this font belongs to. A font family is a set of fonts having common stroke width and serif characteristics. The font name overrides when there are conflicting values.
      Parameters:
      value - - font family
      See Also:
    • setFamily

      public void setFamily(FontFamily family)
      set an enumeration representing the font family this font belongs to. A font family is a set of fonts having common stroke width and serif characteristics.
      Parameters:
      family - font family
      See Also:
    • getIndex

      public int getIndex()
      Description copied from interface: Font
      get the index within the XSSFWorkbook (sequence within the collection of Font objects)
      Specified by:
      getIndex in interface Font
      Returns:
      unique index number of the underlying record this Font represents (probably you don't care unless you're comparing which one is which)
    • getIndexAsInt

      @Deprecated @Removal(version="6.0.0") public int getIndexAsInt()
      Deprecated.
      use getIndex() instead
      Description copied from interface: Font
      get the index within the XSSFWorkbook (sequence within the collection of Font objects)
      Specified by:
      getIndexAsInt in interface Font
      Returns:
      index
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object