The requested page is not available for the requested platform. You are viewing the content for .NET Framework 4.5.2+ platform.
.NET Framework 4.5.2+
.NET Framework 4.5.2+
.NET Standard 2.0+
.NET Core 3.0+
Row

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.v19.2.Core.dll

Declaration

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

Parameters

Name Type Description
name String

A string that specifies the style name.

Parameters

Name Type Description
name String

A string that specifies the style name.

Parameters

Name Type Description
name String

A string that specifies the style name.

Returns

Type Description
Style

A Style object that specifies the new style.

Returns

Type Description
Style

A Style object that specifies the new style.

Returns

Type Description
Style

A Style object that specifies the new style.

Remarks

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.

Examples

  1. Add a new style to the Workbook.Styles collection by calling the StyleCollection.Add method with the style name passed as a parameter. This method returns the Style object corresponding to the created style. This object's Style.Name property is set to the specified name. Other settings are identical to the Normal built-in style.
  2. Use properties of the newly created Style object to set the required format characteristics.
// Add a new style under the "My Style" name to the Styles collection of the workbook.
Style myStyle = workbook.Styles.Add("My Style");

// Specify formatting characteristics for the style.
myStyle.BeginUpdate();
try {
    // Set the font color to Blue.
    myStyle.Font.Color = Color.Blue;

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

    // Set the horizontal alignment to Center.
    myStyle.Alignment.Horizontal = SpreadsheetHorizontalAlignment.Center;

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