Back to Devexpress

Workbook.Styles Property

officefileapi-devexpress-dot-spreadsheet-dot-workbook-b63eb628.md

latest6.8 KB
Original Source

Workbook.Styles Property

Provides access to the workbook’s collection of cell styles.

You need a license for the DevExpress Office File API Subscription or DevExpress Universal Subscription to use this property in production code.

Namespace : DevExpress.Spreadsheet

Assembly : DevExpress.Docs.v25.2.dll

NuGet Package : DevExpress.Document.Processor

Declaration

csharp
public StyleCollection Styles { get; }
vb
Public ReadOnly Property Styles As StyleCollection

Property Value

TypeDescription
StyleCollection

A StyleCollection collection containing cell styles.

|

Remarks

The StyleCollection contains Microsoft® Excel® built-in styles, including the Normal style that is applied to cells by default (StyleCollection.DefaultStyle). You can create custom styles, and copy, modify or delete existing styles (see the How to: Create or Modify a Style example).

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 Workbook.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
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;
vb
Dim worksheet As Worksheet = workbook.Worksheets(0)

' 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

The following code snippets (auto-collected from DevExpress Examples) contain references to the Styles property.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

spreadsheet-document-api-examples-part1/CS/SpreadsheetExamples/SpreadsheetActions/FormattingActions.cs#L27

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

spreadsheet-document-api-examples-part2/CS/SpreadsheetDocServerAPIPart2/CodeExamples/SortActions.cs#L36

csharp
header.ColumnWidthInCharacters = 30;
header.Style = workbook.Styles["Heading 1"];
#endregion #SimpleSort

spreadsheet-document-api-examples-part1/VB/SpreadsheetExamples/SpreadsheetActions/FormattingActions.vb#L33

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 cell range.

spreadsheet-document-api-examples-part2/VB/SpreadsheetDocServerAPIPart2/CodeExamples/SortActions.vb#L33

vb
header.ColumnWidthInCharacters = 30
            header.Style = workbook.Styles("Heading 1")
' #End Region ' #SimpleSort

Implements

Styles

See Also

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

How to: Create or Modify a Cell Style

Workbook Class

Workbook Members

DevExpress.Spreadsheet Namespace