Click or drag to resize

BuiltInCellStyleName Enumeration

Represents a built-in style name.

Namespace:  GemBox.Spreadsheet
Assembly:  GemBox.Spreadsheet (in GemBox.Spreadsheet.dll) Version:
public enum BuiltInCellStyleName
  Member nameValueDescription
Normal0 'Normal' built-in style.
RowLevel11 'RowLevel_1' built-in style.
RowLevel2257 'RowLevel_2' built-in style.
RowLevel3513 'RowLevel_3' built-in style.
RowLevel4769 'RowLevel_4' built-in style.
RowLevel51025 'RowLevel_5' built-in style.
RowLevel61281 'RowLevel_6' built-in style.
RowLevel71537 'RowLevel_7' built-in style.
ColLevel12 'ColLevel_1' built-in style.
ColLevel2258 'ColLevel_2' built-in style.
ColLevel3514 'ColLevel_3' built-in style.
ColLevel4770 'ColLevel_4' built-in style.
ColLevel51026 'ColLevel_5' built-in style.
ColLevel61282 'ColLevel_6' built-in style.
ColLevel71538 'ColLevel_7' built-in style.
Comma3 'Comma' built-in style.
Currency4 'Currency' built-in style.
Percent5 'Percent' built-in style.
Comma06 'Comma [0]' built-in style.
Currency07 'Currency [0]' built-in style.
Hyperlink8Hyperlink built-in style.
FollowedHyperlink9Followed Hyperlink built-in style.
Note10Note built-in style.
WarningText11 'Warning Text' built-in style.
Title15 'Title' built-in style.
Heading116 'Heading 1' built-in style.
Heading217 'Heading 2' built-in style.
Heading318 'Heading 3' built-in style.
Heading419 'Heading 4' built-in style.
Input20 'Input' built-in style.
Output21 'Output' built-in style.
Calculation22 'Calculation' built-in style.
CheckCell23 'Check Cell' built-in style.
LinkedCell24 'Linked Cell' built-in style.
Total25 'Total' built-in style.
Good26 'Good' built-in style.
Bad27 'Bad' built-in style.
Neutral28 'Neutral' built-in style.
Accent129 'Accent1' built-in style.
Accent1Pct2030 '20% - Accent1' built-in style.
Accent1Pct4031 '40% - Accent1' built-in style.
Accent1Pct6032 '60% - Accent1' built-in style.
Accent233 'Accent2' built-in style.
Accent2Pct2034 '20% - Accent2' built-in style.
Accent2Pct4035 '40% - Accent2' built-in style.
Accent2Pct6036 '60% - Accent2' built-in style.
Accent337 'Accent3' built-in style.
Accent3Pct2038 '20% - Accent3' built-in style.
Accent3Pct4039 '40% - Accent3' built-in style.
Accent3Pct6040 '60% - Accent3' built-in style.
Accent441 'Accent4' built-in style.
Accent4Pct2042 '20% - Accent4' built-in style.
Accent4Pct4043 '40% - Accent4' built-in style.
Accent4Pct6044 '60% - Accent4' built-in style.
Accent545 'Accent5' built-in style.
Accent5Pct2046 '20% - Accent5' built-in style.
Accent5Pct4047 '40% - Accent5' built-in style.
Accent5Pct6048 '60% - Accent5' built-in style.
Accent649 'Accent6' built-in style.
Accent6Pct2050 '20% - Accent6' built-in style.
Accent6Pct4051 '40% - Accent6' built-in style.
Accent6Pct6052 '60% - Accent6' built-in style.
ExplanatoryText53 'Explanatory Text' built-in style.

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 how to set workbook style to a range of cells:

// Set 'Good' style to all cells of the first sheet.
workbook.Worksheets[0].Cells.Style = workbook.Styles[BuiltInCellStyleName.Good];

Following code demonstrates when not to and when to initialize a new instance of the CellStyle class:

// To modify a single formatting property on a range of cells, simply modify it.
// Other formatting properties will remain unchanged.
sheet.Cells.Style.Font.Italic = true;

// To modify multiple formatting properties on a range of cells, create new CellStyle instance, modify it, and assign it to a range of cells.
// All formatting properties are changed.
sheet.Cells.Style = new CellStyle(sheet.Parent)
    NumberFormat = "#,##0.00",
    HorizontalAlignment = HorizontalAlignmentStyle.Center,
    Locked = false

Following code demonstrates cell formatting:

var cells = sheet.Cells;

// 'Number' formatting group

cells["B3"].Value = "NumberFormat";
cells["C3"].Value = 1234;
cells["C3"].Style.NumberFormat = "#.##0,00 [$Krakozhian Money Units]";

// 'Alignment' formatting group

cells["B5"].Value = "HorizontalAlignment = ";
cells["C5"].Value = "HorizontalAlignmentStyle.Center";
cells["C5"].Style.HorizontalAlignment = HorizontalAlignmentStyle.Center;

cells["B6"].Value = "VerticalAlignment = ";
cells["C6"].Value = "VerticalAlignmentStyle.Top";
cells["C6"].Style.VerticalAlignment = VerticalAlignmentStyle.Top;
// Set row height to 30 points.
sheet.Rows["6"].Height = 30 * 20;

cells["B7"].Value = "Indent";
cells["C7"].Value = "five";
cells["C7"].Style.Indent = 5;
cells["C7"].Style.HorizontalAlignment = HorizontalAlignmentStyle.Left;

cells["B8"].Value = "Rotation";
cells["C8"].Value = "35 degrees up";
cells["C8"].Style.Rotation = 35;

cells["B9"].Value = "IsTextVertical = ";
cells["C9"].Value = "true";
cells["C9"].Style.IsTextVertical = true;

cells["B10"].Value = "WrapText";
cells["C10"].Value = "This property is set to true so this text appears broken into multiple lines.";
cells["C10"].Style.WrapText = true;

cells["B11"].Value = "ShrinkToFit";
cells["C11"].Value = "This property is set to true so this text appears shrunk.";
cells["C11"].Style.ShrinkToFit = true;

// '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;

// 'Border' formatting group

cells["B22"].Value = "Borders.SetBorders(...)";
cells["C22"].Style.Borders.SetBorders(MultipleBorders.All, SpreadsheetColor.FromName(ColorName.Accent2), LineStyle.Thin);

// 'Fill' formatting group

cells["B24"].Value = "FillPattern.SetPattern(...)";
cells["C24"].Style.FillPattern.SetPattern(FillPatternStyle.ThinHorizontalCrosshatch, SpreadsheetColor.FromName(ColorName.Green), SpreadsheetColor.FromName(ColorName.Yellow));

cells["B25"].Value = "FillPattern.SetGradient(...)";
cells["C25"].Style.FillPattern.SetGradient(GradientShadingStyle.HorizontalHigh, SpreadsheetColor.FromName(ColorName.Green), SpreadsheetColor.FromName(ColorName.Yellow));

// 'Protection' formatting group

cells["B27"].Value = "Locked = ";
cells["C27"].Value = "false";
cells["C27"].Style.Locked = false;

cells["B28"].Value = "FormulaHidden = ";
cells["C28"].Value = "true";
cells["C28"].Style.FormulaHidden = true;
See Also