.NET Framework 4.5.2+
.NET Framework 4.5.2+
.NET Standard 2.0+

StyleCollection.Add(String) Method

Creates a new style with the specified name and appends it to the style collection.

Namespace: DevExpress.Spreadsheet

Assembly: DevExpress.Spreadsheet.v20.1.Core.dll


Style Add(
    string name
Function Add(
    name As String
) As Style


Name Type Description
name String

A string that specifies the style name.


Type Description

A Style object that specifies the new style.


A workbook's style collection (IWorkbook.Styles) contains Microsoft® Excel® built-in styles by default. The BuiltInStyleId enumerator lists these predefined styles. You can use the Add method to extend the style collection with custom styles.

When you name a style, take into account the following restrictions:

All settings of the created Style object except name (Style.Name) are the same as in the Normal default style. To set required formatting characteristics for the style, modify the corresponding properties of the Style object within the Formatting.BeginUpdate - Formatting.EndUpdate paired method calls.

To create a new style based on the existing style, use the Style.CopyFrom method.

For details on how to create and modify styles, see the How to: Create or Modify a Style document.


Use the StyleCollection.Add method of the Workbook.Styles collection to create a new style with a given name. The style's format settings are identical to the Normal built-in style. Use the Style object's properties to specify format characteristics for the new style.

// Add a new style under the "My Style" name to the style collection.
Style myStyle = workbook.Styles.Add("My Style");

// Specify the style's format characteristics.
try {
    // Set the font color to blue.
    myStyle.Font.Color = Color.Blue;

    // Set the font size to 12.
    myStyle.Font.Size = 12;

    // Center text in cells.
    myStyle.Alignment.Horizontal = SpreadsheetHorizontalAlignment.Center;

    // Set the background fill.
    myStyle.Fill.BackgroundColor = Color.LightBlue;
    myStyle.Fill.PatternType = PatternType.LightGray;
    myStyle.Fill.PatternColor = Color.Yellow;
finally {
See Also