Click or drag to resize

ExcelFont Class

Represents a typeface (for example, Calibri), along with its attributes (size, font style, underlining, color, and effects).
Inheritance Hierarchy

Namespace:  GemBox.Spreadsheet
Assembly:  GemBox.Spreadsheet (in GemBox.Spreadsheet.dll) Version:
public sealed class ExcelFont

The ExcelFont type exposes the following members.

Public methodExcelFont
Initializes a new instance of the ExcelFont class.
Public propertyCode exampleColor

Gets or sets the color of the text.

Default value is color created from name Text1.

Public propertyCode exampleItalic

Gets or sets a value indicating whether to display characters in italic font style.

Default value is .

Public propertyCode exampleName

Gets or sets the face name of this font.

Default value is Calibri.

Public propertyCode exampleScriptPosition

Gets or sets the vertical position of the text relative to the text's default appearance.

Default value is Normal.

Public propertyCode exampleSize

Gets or sets the size of the text in twips (1/20th of a point).

Default value is 11 * 20 = 220.

Public propertyCode exampleStrikeout

Gets or sets a value indicating whether to draw a strike-through line through the horizontal middle of the text.

Default value is .

Public propertyCode exampleUnderlineStyle

Gets or sets the underline formatting of the text.

Default value is None.

Public propertyCode exampleWeight

Gets or sets the font weight (font boldness).

Value must be between MinWeight and MaxWeight.

For standard boldness, use BoldWeight.

Default value is NormalWeight.

Public fieldStatic memberBoldWeight
Default bold font weight.
Public fieldStatic memberMaxWeight
Maximum font weight.
Public fieldStatic memberMinWeight
Minimum font weight.
Public fieldStatic memberNormalWeight
Normal font weight.

Conceptually, cell formatting is divided into following groups:

  • Number - indicates how to format and render the numeric value of a cell. Associated property is NumberFormat.
  • Alignment - formatting information pertaining to text alignment in cells. Associated properties are HorizontalAlignment, VerticalAlignment, Indent, Rotation, IsTextVertical, WrapText and ShrinkToFit.
  • Font - defines the properties for the used font. Associated property is Font.
  • Border - expresses a single set of cell border formats (left, right, top, bottom and diagonal). Associated property is Borders.
  • Fill - specifies fill formatting (pattern or gradient). Associated property is FillPattern.
  • Protection - contains protection properties associated with the cell. Associated properties are Locked and FormulaHidden.

Additional CellStyle properties not associated with any formatting group are:

  • Name - name of the referenced workbook style.
  • QuotePrefix - to store numeric value of a cell as text; otherwise, .
  • IsDefault - if referenced workbook style is default (Normal) and there are no additional modifications of cell formatting; otherwise, .

Workbook contains a set of master styles which can be referenced by multiple cells.

Workbook must always contain at least one master style which cannot be removed and is, by default, referenced by all cells. This default style is Normal.

Workbook style can either be built-in or user-defined. Built-in style is accessible from workbook styles via BuiltInCellStyleName enumeration.

Cell formatting group (Number, Alignment, Font, Border, Fill or Protection) (and its associated properties) is resolved from referenced workbook (master) style, unless cell formatting group or its associated property is modified.

Cell formatting is available for one or more cells through Style property which is available on ExcelCell and CellRange types. Cell formatting specified on ExcelColumn and ExcelRow types through Style property is simply propagated to cell formatting of its Cells.

Note Note

For performance reasons, cell formatting on CellRange is resolved based just on its top-left cell formatting, except borders which are resolved based on corner cells depending on border side.

Setting cell formatting property on CellRange is propagated to each cell in a range.

To set workbook (master) style to one or more cells, simply assign it to Style property.

Tip Tip

Preferable way to modify formatting property of multiple cells is to get CellRange to which all those cells belong, and use Style property of that range to make the modification.

If modifying multiple formatting properties of a CellRange, without preserving unmodified formatting properties, preferable way is to create new instance of CellStyle, make modifications on it, and assign it to Style property of that range.

GemBox.Spreadsheet internally takes care not to allocate unnecessary cells when formatting a range of cells (for example, when formatting all worksheet cells) and to cache formatting information of equally formatted cells, at the appropriate time, to reduce memory footprint.


Following code demonstrates font formatting:

// 'Font' formatting group

cells["B13"].Value = "Font.Name = ";
cells["C13"].Value = "Comic Sans MS";
cells["C13"].Style.Font.Name = "Comic Sans MS";

cells["B14"].Value = "Font.Italic = ";
cells["C14"].Value = "true";
cells["C14"].Style.Font.Italic = true;

cells["B15"].Value = "Font.Weight = ";
cells["C15"].Value = "ExcelFont.BoldWeight";
cells["C15"].Style.Font.Weight = ExcelFont.BoldWeight;

cells["B16"].Value = "Font.Size = ";
cells["C16"].Value = "18 * 20";
cells["C16"].Style.Font.Size = 18 * 20;

cells["B17"].Value = "Font.Color";
cells["C17"].Value = "Text2";
cells["C17"].Style.Font.Color = SpreadsheetColor.FromName(ColorName.Text2);

cells["B18"].Value = "Font.UnderlineStyle = ";
cells["C18"].Value = "UnderlineStyle.Double";
cells["C18"].Style.Font.UnderlineStyle = UnderlineStyle.Double;

cells["B19"].Value = "Font.Strikeout = ";
cells["C19"].Value = "true";
cells["C19"].Style.Font.Strikeout = true;

cells["B20"].Value = "Font.ScriptPosition = ";
cells["C20"].Value = "ScriptPosition.Superscript";
cells["C20"].Style.Font.ScriptPosition = ScriptPosition.Superscript;
See Also