[]
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());
booleangetBold()getColor()intbooleangetName()doublegetSize()booleanbooleanbooleandoublevoidsetBold(boolean value) voidvoidsetColorIndex(int value) voidsetItalic(boolean value) voidvoidsetSize(double value) voidsetStrikethrough(boolean value) voidsetSubscript(boolean value) voidsetSuperscript(boolean value) voidsetThemeColor(ThemeColor value) voidsetThemeFont(ThemeFont value) voidsetTintAndShade(double value) voidsetUnderline(UnderlineType value) 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();
true if the font is bold; otherwise, false.
IRange cell = worksheet.getRange("A1");
cell.setValue("Title");
cell.getFont().setBold(true);
value - true if the font is bold; otherwise, false.
IRange cell = worksheet.getRange("A1");
cell.setValue("Title");
IFont font = cell.getFont();
font.setColor(Color.GetRed());
Color color = font.getColor();
IRange cell = worksheet.getRange("A1");
cell.setValue("Title");
IFont font = cell.getFont();
font.setColor(Color.GetRed());
value - The font color.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());
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());
value - The color index used for the font.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();
true if the font style is italic; otherwise, false.
IRange cell = worksheet.getRange("A1");
cell.setValue("Title");
cell.getFont().setItalic(true);
value - true if the font style is italic; otherwise, false.
IRange cell = worksheet.getRange("A1");
cell.setValue("Title");
cell.getFont().setName("Arial");
String fontName = cell.getFont().getName();
IRange cell = worksheet.getRange("A1");
cell.setValue("Title");
cell.getFont().setName("Arial");
value - The font family name.
IFont font = worksheet.getRange("A1").getFont();
font.setSize(14);
double size = font.getSize();
IFont font = worksheet.getRange("A1").getFont();
font.setSize(14);
value - The font size, in points.
IFont font = worksheet.getRange("A1").getFont();
font.setStrikethrough(true);
boolean strikethrough = font.getStrikethrough();
true if strikethrough formatting is applied to the font; otherwise, false.
IFont font = worksheet.getRange("A1").getFont();
font.setStrikethrough(true);
value - true to apply strikethrough formatting to the font; otherwise, false.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();
true if subscript formatting is applied to the font; otherwise, false.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);
value - true to apply subscript formatting to the font; otherwise, false.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();
true if superscript formatting is applied to the font; otherwise, false.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);
value - true to apply superscript formatting to the font; otherwise, false.
IFont font = worksheet.getRange("A1").getFont();
font.setThemeColor(ThemeColor.Accent1);
ThemeColor themeColor = font.getThemeColor();
IFont font = worksheet.getRange("A1").getFont();
font.setThemeColor(ThemeColor.Accent1);
value - The theme color used for 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();
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);
value - The tint and shade adjustment applied to the font color.IllegalArgumentException - if value is less than -1.0 or greater than 1.0.
IFont font = worksheet.getRange("A1").getFont();
font.setUnderline(UnderlineType.Single);
UnderlineType underline = font.getUnderline();
IFont font = worksheet.getRange("A1").getFont();
font.setUnderline(UnderlineType.Single);
value - The underline type for 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();
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);
value - The theme font used by the font.