TRY NEW VERSION

Try now New API BETA

Try out the new view and capabilities of the API documentation

START

ApiFont

new ApiFont()

Class that contains the font attributes (font name, font size, color, and so on).

Properties

Name Type Description
Parent ApiCharacters

The parent object of the specified font object.

Bold boolean | null

The font bold property.

Italic boolean | null

The font italic property.

Size number | null

The font size property.

Strikethrough boolean | null

The font strikethrough property.

Underline string | null

The font type of underline.

Subscript boolean | null

The font subscript property.

Superscript boolean | null

The font superscript property.

Name string | null

The font name.

Color ApiColor | null

The font color property.

Methods

Name Description
GetBold

Returns the bold property of the specified font.

GetColor

Returns the font color property of the specified font.

GetItalic

Returns the italic property of the specified font.

GetName

Returns the font name property of the specified font.

GetParent

Returns the parent ApiCharacters object of the specified font.

GetSize

Returns the font size property of the specified font.

GetStrikethrough

Returns the strikethrough property of the specified font.

GetSubscript

Returns the subscript property of the specified font.

GetSuperscript

Returns the superscript property of the specified font.

GetUnderline

Returns the type of underline applied to the specified font.

SetBold

Sets the bold property to the specified font. This method will work only with the text format of the cell.

SetColor

Sets the font color property to the specified font. This method will work only with the text format of the cell.

SetItalic

Sets the italic property to the specified font. This method will work only with the text format of the cell.

SetName

Sets the font name property to the specified font. This method will work only with the text format of the cell.

SetSize

Sets the font size property to the specified font. This method will work only with the text format of the cell.

SetStrikethrough

Sets the strikethrough property to the specified font. This method will work only with the text format of the cell.

SetSubscript

Sets the subscript property to the specified font. This method will work only with the text format of the cell.

SetSuperscript

Sets the superscript property to the specified font. This method will work only with the text format of the cell.

SetUnderline

Sets an underline of the type specified in the request to the current font. This method will work only with the text format of the cell.

Example

Copy code
builder.CreateFile("xlsx");
var oWorksheet = Api.GetActiveSheet();
var oRange = oWorksheet.GetRange("B1");
oRange.SetValue("This is just a sample text.");
var oCharacters = oRange.GetCharacters(23, 6);
var oFont = oCharacters.GetFont();
var oParent = oFont.GetParent();
oParent.SetText("string");
oFont.SetSize(18);
oFont.SetStrikethrough(true);
oFont.SetName("Font 1");
oFont.SetItalic(true);
var sFontName = oFont.GetName();
oWorksheet.GetRange("B3").SetValue("Font name: " + sFontName);
var nSize = oFont.GetSize();
oWorksheet.GetRange("B4").SetValue("Size property: " + nSize);
var bStrikethrough = oFont.GetStrikethrough();
oWorksheet.GetRange("B5").SetValue("Strikethrough property: " + bStrikethrough);
var bItalic = oFont.GetItalic();
oWorksheet.GetRange("B9").SetValue("Italic property: " + bItalic);
oCharacters = oRange.GetCharacters(9, 4);
oFont = oCharacters.GetFont();
oFont.SetSubscript(true);
var bSubscript = oFont.GetSubscript();
oWorksheet.GetRange("B6").SetValue("Subscript property: " + bSubscript);
var oColor = Api.CreateColorFromRGB(255, 111, 61);
oFont.SetColor(oColor);
oColor = oFont.GetColor();
oCharacters = oRange.GetCharacters(16, 6);
oFont = oCharacters.GetFont();
oFont.SetColor(oColor);
oCharacters = oRange.GetCharacters(6, 2);
oFont = oCharacters.GetFont();
oFont.SetSuperscript(true);
oFont.SetUnderline("xlUnderlineStyleSingle");
oFont.SetBold(true);
var bSuperscript = oFont.GetSuperscript();
oWorksheet.GetRange("B7").SetValue("Superscript property: " + bSuperscript);
var sUnderline = oFont.GetUnderline();
oWorksheet.GetRange("B8").SetValue("Underline property: " + sUnderline);
var bBold = oFont.GetBold();
oWorksheet.GetRange("B10").SetValue("Bold property: " + bBold);
builder.SaveFile("xlsx", "ApiFont.xlsx");
builder.CloseFile();

Resulting document