StyleCollection.Item[String] Property
Provides access to individual cell styles in the collection by their names.
Namespace: DevExpress.Spreadsheet
Assembly: DevExpress.Spreadsheet.v24.2.Core.dll
NuGet Package: DevExpress.Spreadsheet.Core
Declaration
Parameters
Name | Type | Description |
---|---|---|
name | String | A String value specifying the name of the style to be found. |
Property Value
Type | Description |
---|---|
Style | A Style object representing the style with the specified name. |
Remarks
Use the Item property to obtain a style by its name from the workbook’s collection of styles (IWorkbook.Styles). When searching, the name parameter value is compared with the Style.Name property of style objects. If no matches are found, an exception is thrown. To check whether a style with the specified name exists in the collection, use the StyleCollection.Contains property.
You can also access a style by its index in the collection. The built-in styles can be accessed by their identifiers listed in the BuiltInStyleId enumerator.
Example
This example demonstrates how to format a cell, a range of cells, an entire row or an entire column by applying a style.
- 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 Workbook.Styles collection.
- Assign the required style object to the CellRange.Style property of the cell, cell range, row or column object.
Worksheet worksheet = workbook.Worksheets[0];
// 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;