Back to Devexpress

StyleCollection.Item[BuiltInStyleId] Property

officefileapi-devexpress-dot-spreadsheet-dot-stylecollection-dot-item-x28-devexpress-dot-spreadsheet-dot-builtinstyleid-x29.md

latest4.4 KB
Original Source

StyleCollection.Item[BuiltInStyleId] Property

Provides access to individual built-in styles in the collection by their identifiers.

Namespace : DevExpress.Spreadsheet

Assembly : DevExpress.Spreadsheet.v25.2.Core.dll

NuGet Package : DevExpress.Spreadsheet.Core

Declaration

csharp
Style this[BuiltInStyleId id] { get; }
vb
ReadOnly Property Item(id As BuiltInStyleId) As Style

Parameters

NameTypeDescription
idBuiltInStyleId

An identifier of the built-in style to return.

|

Property Value

TypeDescription
Style

The built-in style with the specified identifier.

|

Remarks

The IWorkbook.Styles collection contains built-in cell styles similar to Microsoft® Excel®. You can obtain these styles by their identifiers (the BuiltInStyleId enumeration members).

You can also access a style by its name or index in the collection.

Example

This example demonstrates how to format a cell, a range of cells, an entire row or an entire column by applying a style.

  1. Access the Style object that specifies the style to be applied to a cell or a range of cells. This style should be added to the IWorkbook.Styles collection.
  2. Assign the required style object to the CellRange.Style property of the cell, cell range, row or column object.

View Example

csharp
// Access the built-in "Good" MS Excel style from the Styles collection of the workbook.
Style styleGood = workbook.Styles[BuiltInStyleId.Good];

// Apply the "Good" style to a range of cells.
worksheet.Range["A1:C4"].Style = styleGood;

// Access a custom style that has been previously created in the loaded document by its name.
Style customStyle = workbook.Styles["Custom Style"];

// Apply the custom style to the cell.
worksheet.Cells["D6"].Style = customStyle;

// Apply the "Good" style to the eighth row.
worksheet.Rows[7].Style = styleGood;

// Apply the custom style to the "H" column.
worksheet.Columns["H"].Style = customStyle;
vb
' Access the built-in "Good" MS Excel style from the Styles collection of the workbook.
Dim styleGood As Style = workbook.Styles(BuiltInStyleId.Good)

' Apply the "Good" style to a range of cells.
worksheet.Range("A1:C4").Style = styleGood

' Access a custom style that has been previously created in the loaded document by its name.
Dim customStyle As Style = workbook.Styles("Custom Style")

' Apply the custom style to the cell.
worksheet.Cells("D6").Style = customStyle

' Apply the "Good" style to the eighth row.
worksheet.Rows(7).Style = styleGood

' Apply the custom style to the "H" column.
worksheet.Columns("H").Style = customStyle

See Also

Format Spreadsheet Cells

How to: Apply a Style to a Cell or Range of Cells

How to: Create or Modify a Cell Style

StyleCollection Interface

StyleCollection Members

DevExpress.Spreadsheet Namespace