All docs
V20.1
20.1
19.2
19.1
The page you are viewing does not exist in version 19.1. This link will take you to the root page.
18.2
The page you are viewing does not exist in version 18.2. This link will take you to the root page.
18.1
The page you are viewing does not exist in version 18.1. This link will take you to the root page.
17.2
The page you are viewing does not exist in version 17.2. This link will take you to the root page.
.NET Framework 4.5.2+
.NET Framework 4.5.2+
.NET Standard 2.0+
Row

StyleCollection.Add(String, CellRange) Method

Creates a new style based on format settings of the specified cell range.

Namespace: DevExpress.Spreadsheet

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

Declaration

Style Add(
    string name,
    CellRange range
)
Function Add(
    name As String,
    range As CellRange
) As Style

Parameters

Name Type Description
name String

A style name.

range CellRange

A cell range whose top left cell contains format settings for a new style.

Returns

Type Description
Style

The newly created cell style.

Exceptions

Type Description
ArgumentNullException

Occurs when a style name is empty or an object passed as the range parameter is null (Nothing in Visual Basic).

InvalidOperationException

Occurs when a style with the same name already exists in the collection.

Remarks

Use this Add method overload to create a new custom style based on existing cell formatting. Format settings are obtained from the top-left cell of the specified cell range. If the source cell has no formatting applied, the Spreadsheet creates a cell style with format settings identical to the Normal built-in style.

Take into account the following rules when you name a new style:

  • A style name must be unique. Use the StyleCollection.Contains method to ensure that the collection does not contain a style with the specified name.

  • A style name cannot be empty.

The new style has all StyleFlags set to true. To change the style's format characteristics, modify the Style object's properties within the Formatting.BeginUpdate - Formatting.EndUpdate method calls.


// Create a style based on format settings of the "B2" cell.
Style customStyle = workbook.Styles.Add("Custom Style", worksheet["B2"]);

// Modify the style's format characteristics if needed.
// ...

See how to create or modify a style.

See Also