[]
        
(Showing Draft Content)

IFont

Interface IFont


public interface IFont
Represents font formatting for a range, style, or text run.

Use this interface to get or set font properties such as name, size, bold, italic, underline, strikethrough, font color, theme color, theme font, and subscript or superscript formatting.


 IRange cell = worksheet.getRange("A1");
 cell.setValue("Title");

 IFont font = cell.getFont();
 font.setName("Arial");
 font.setSize(14);
 font.setBold(true);
 font.setColor(Color.GetRed());
 
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    Gets whether the font is bold.
    Gets the font color.
    int
    Gets the color index used for the font.
    boolean
    Gets whether the font style is italic.
    Gets the font family name.
    double
    Gets the font size, in points.
    boolean
    Gets whether strikethrough formatting is applied to the font.
    boolean
    Gets whether subscript formatting is applied to the font.
    boolean
    Gets whether superscript formatting is applied to the font.
    Gets the theme color used for the font color.
    Gets the theme font used by the font.
    double
    Gets the tint and shade adjustment applied to the font color.
    Gets the underline type for the font.
    void
    setBold(boolean value)
    Sets whether the font is bold.
    void
    setColor(Color value)
    Sets the font color.
    void
    setColorIndex(int value)
    Sets the color index used for the font.
    void
    setItalic(boolean value)
    Sets whether the font style is italic.
    void
    setName(String value)
    Sets the font family name.
    void
    setSize(double value)
    Sets the font size, in points.
    void
    setStrikethrough(boolean value)
    Sets whether strikethrough formatting is applied to the font.
    void
    setSubscript(boolean value)
    Sets whether subscript formatting is applied to the font.
    void
    setSuperscript(boolean value)
    Sets whether superscript formatting is applied to the font.
    void
    Sets the theme color used for the font color.
    void
    Sets the theme font used by the font.
    void
    setTintAndShade(double value)
    Sets the tint and shade adjustment applied to the font color.
    void
    Sets the underline type for the font.
  • Method Details

    • getBold

      boolean getBold()
      Gets whether the font is bold.

      This property indicates whether bold formatting is applied to the represented text. Use setBold(boolean) to change the bold state.

      
       IRange cell = worksheet.getRange("A1");
       cell.setValue("Title");
       cell.getFont().setBold(true);
       boolean bold = cell.getFont().getBold();
       
      Returns:
      true if the font is bold; otherwise, false.
    • setBold

      void setBold(boolean value)
      Sets whether the font is bold.
      
       IRange cell = worksheet.getRange("A1");
       cell.setValue("Title");
       cell.getFont().setBold(true);
       
      Parameters:
      value - true if the font is bold; otherwise, false.
    • getColor

      Color getColor()
      Gets the font color.
      
       IRange cell = worksheet.getRange("A1");
       cell.setValue("Title");
      
       IFont font = cell.getFont();
       font.setColor(Color.GetRed());
      
       Color color = font.getColor();
       
      Returns:
      The font color.
    • setColor

      void setColor(Color value)
      Sets the font color.
      
       IRange cell = worksheet.getRange("A1");
       cell.setValue("Title");
      
       IFont font = cell.getFont();
       font.setColor(Color.GetRed());
       
      Parameters:
      value - The font color.
    • getColorIndex

      int getColorIndex()
      Gets the color index used for the font.

      The value can be a palette color index or a special color index value such as ColorDataIndex.Automatic.

      
       IFont font = worksheet.getRange("A1").getFont();
      
       // Use a special color index value.
       font.setColorIndex(ColorDataIndex.Automatic.getValue());
      
       ColorDataIndex colorIndex = ColorDataIndex.forValue(font.getColorIndex());
       
      Returns:
      The color index used for the font.
    • setColorIndex

      void setColorIndex(int value)
      Sets the color index used for the font.

      The value can be a palette color index or a special color index value such as ColorDataIndex.Automatic.

      
       IFont font = worksheet.getRange("A1").getFont();
      
       // Use a special color index value.
       font.setColorIndex(ColorDataIndex.Automatic.getValue());
       
      Parameters:
      value - The color index used for the font.
    • getItalic

      boolean getItalic()
      Gets whether the font style is italic.

      This property indicates whether italic formatting is applied to the represented text. Use setItalic(boolean) to change the italic state.

      
       IRange cell = worksheet.getRange("A1");
       cell.setValue("Title");
       cell.getFont().setItalic(true);
       boolean italic = cell.getFont().getItalic();
       
      Returns:
      true if the font style is italic; otherwise, false.
    • setItalic

      void setItalic(boolean value)
      Sets whether the font style is italic.
      
       IRange cell = worksheet.getRange("A1");
       cell.setValue("Title");
       cell.getFont().setItalic(true);
       
      Parameters:
      value - true if the font style is italic; otherwise, false.
    • getName

      String getName()
      Gets the font family name.
      
       IRange cell = worksheet.getRange("A1");
       cell.setValue("Title");
       cell.getFont().setName("Arial");
       String fontName = cell.getFont().getName();
       
      Returns:
      The font family name.
    • setName

      void setName(String value)
      Sets the font family name.
      
       IRange cell = worksheet.getRange("A1");
       cell.setValue("Title");
       cell.getFont().setName("Arial");
       
      Parameters:
      value - The font family name.
    • getSize

      double getSize()
      Gets the font size, in points.
      
       IFont font = worksheet.getRange("A1").getFont();
       font.setSize(14);
       double size = font.getSize();
       
      Returns:
      The font size, in points.
    • setSize

      void setSize(double value)
      Sets the font size, in points.
      
       IFont font = worksheet.getRange("A1").getFont();
       font.setSize(14);
       
      Parameters:
      value - The font size, in points.
    • getStrikethrough

      boolean getStrikethrough()
      Gets whether strikethrough formatting is applied to the font.
      
       IFont font = worksheet.getRange("A1").getFont();
       font.setStrikethrough(true);
      
       boolean strikethrough = font.getStrikethrough();
       
      Returns:
      true if strikethrough formatting is applied to the font; otherwise, false.
    • setStrikethrough

      void setStrikethrough(boolean value)
      Sets whether strikethrough formatting is applied to the font.
      
       IFont font = worksheet.getRange("A1").getFont();
       font.setStrikethrough(true);
       
      Parameters:
      value - true to apply strikethrough formatting to the font; otherwise, false.
    • getSubscript

      boolean getSubscript()
      Gets whether subscript formatting is applied to the font.

      Setting this formatting on IRange.getFont() affects all text in the range. To format only part of the text, call IRange.characters(int,int) to get an ITextRun, and then call ITextRun.getFont().

      
       IRange cell = worksheet.getRange("A1");
       cell.setValue("H2O");
      
       // Apply subscript only to "2".
       IFont font = cell.characters(1, 1).getFont();
       font.setSubscript(true);
      
       boolean subscript = font.getSubscript();
       
      Returns:
      true if subscript formatting is applied to the font; otherwise, false.
    • setSubscript

      void setSubscript(boolean value)
      Sets whether subscript formatting is applied to the font.

      Setting this formatting on IRange.getFont() affects all text in the range. To format only part of the text, call IRange.characters(int,int) to get an ITextRun, and then call ITextRun.getFont().

      
       IRange cell = worksheet.getRange("A1");
       cell.setValue("H2O");
      
       // Apply subscript only to "2".
       IFont font = cell.characters(1, 1).getFont();
       font.setSubscript(true);
       
      Parameters:
      value - true to apply subscript formatting to the font; otherwise, false.
    • getSuperscript

      boolean getSuperscript()
      Gets whether superscript formatting is applied to the font.

      Setting this formatting on IRange.getFont() affects all text in the range. To format only part of the text, call IRange.characters(int,int) to get an ITextRun, and then call ITextRun.getFont().

      
       IRange cell = worksheet.getRange("A1");
       cell.setValue("E=mc2");
      
       // Apply superscript only to "2".
       IFont font = cell.characters(5, 1).getFont();
       font.setSuperscript(true);
      
       boolean superscript = font.getSuperscript();
       
      Returns:
      true if superscript formatting is applied to the font; otherwise, false.
    • setSuperscript

      void setSuperscript(boolean value)
      Sets whether superscript formatting is applied to the font.

      Setting this formatting on IRange.getFont() affects all text in the range. To format only part of the text, call IRange.characters(int,int) to get an ITextRun, and then call ITextRun.getFont().

      
       IRange cell = worksheet.getRange("A1");
       cell.setValue("E=mc2");
      
       // Apply superscript only to "2".
       IFont font = cell.characters(5, 1).getFont();
       font.setSuperscript(true);
       
      Parameters:
      value - true to apply superscript formatting to the font; otherwise, false.
    • getThemeColor

      ThemeColor getThemeColor()
      Gets the theme color used for the font color.
      
       IFont font = worksheet.getRange("A1").getFont();
       font.setThemeColor(ThemeColor.Accent1);
       ThemeColor themeColor = font.getThemeColor();
       
      Returns:
      The theme color used for the font color.
    • setThemeColor

      void setThemeColor(ThemeColor value)
      Sets the theme color used for the font color.
      
       IFont font = worksheet.getRange("A1").getFont();
       font.setThemeColor(ThemeColor.Accent1);
       
      Parameters:
      value - The theme color used for the font color.
    • getTintAndShade

      double getTintAndShade()
      Gets the tint and shade adjustment applied to the font color.

      The value must be from -1.0 to 1.0, where 0 is neutral.

      
       IFont font = worksheet.getRange("A1").getFont();
       font.setThemeColor(ThemeColor.Accent1);
       font.setTintAndShade(0.5);
       double tintAndShade = font.getTintAndShade();
       
      Returns:
      The tint and shade adjustment applied to the font color.
    • setTintAndShade

      void setTintAndShade(double value)
      Sets the tint and shade adjustment applied to the font color.

      The value must be from -1.0 to 1.0, where 0 is neutral; otherwise, an IllegalArgumentException is thrown.

      
       IFont font = worksheet.getRange("A1").getFont();
       font.setThemeColor(ThemeColor.Accent1);
       font.setTintAndShade(0.5);
       
      Parameters:
      value - The tint and shade adjustment applied to the font color.
      Throws:
      IllegalArgumentException - if value is less than -1.0 or greater than 1.0.
    • getUnderline

      UnderlineType getUnderline()
      Gets the underline type for the font.
      
       IFont font = worksheet.getRange("A1").getFont();
       font.setUnderline(UnderlineType.Single);
       UnderlineType underline = font.getUnderline();
       
      Returns:
      The underline type for the font.
    • setUnderline

      void setUnderline(UnderlineType value)
      Sets the underline type for the font.
      
       IFont font = worksheet.getRange("A1").getFont();
       font.setUnderline(UnderlineType.Single);
       
      Parameters:
      value - The underline type for the font.
    • getThemeFont

      ThemeFont getThemeFont()
      Gets the theme font used by the font.

      Use ThemeFont.Major or ThemeFont.Minor to follow the workbook theme font scheme, or ThemeFont.None to use a non-theme font.

      
       IFont font = worksheet.getRange("A1").getFont();
       font.setThemeFont(ThemeFont.Major);
       ThemeFont themeFont = font.getThemeFont();
       
      Returns:
      The theme font used by the font.
    • setThemeFont

      void setThemeFont(ThemeFont value)
      Sets the theme font used by the font.

      Use ThemeFont.Major or ThemeFont.Minor to follow the workbook theme font scheme, or ThemeFont.None to use a non-theme font.

      
       IFont font = worksheet.getRange("A1").getFont();
       font.setThemeFont(ThemeFont.Major);
       
      Parameters:
      value - The theme font used by the font.