.NET Framework 4.5.2+
.NET Framework 4.5.2+
.NET Standard 2.0+
Row

TableStyleCollection.Item[String] Property

Returns the table style or PivotTable style by its name.

Namespace: DevExpress.Spreadsheet

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

Declaration

TableStyle this[string name] { get; }

Parameters

Name Type Description
name String

A String value specifying the name of the style to be found.

Property Value

Type Description
TableStyle

A TableStyle object specifying the table or pivot table style with the specified name.

Remarks

Use the Item property to obtain a table or pivot table style by its name from the workbook’s collection of styles. When searching, the name parameter value is compared to the TableStyle.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 TableStyleCollection.Contains property.

Built-in table and pivot table styles can be also accessed by their IDs specified by the BuiltInTableStyleId and DevExpress.Spreadsheet.BuiltInPivotStyleId enumerator members, respectively.

Example

To format a table by applying a table style, assign the corresponding TableStyle object to the Table.Style property. Access the required table style object from the IWorkbook.TableStyles collection by the table style name. Built-in table styles can also be obtained by their ids (the BuiltInTableStyleId enumeration members).

A table style consists of the collection of table style elements (TableStyle.TableStyleElements). Each table style element (TableStyleElement) specifies the formatting for a particular element of a table. The TableStyleElementType enumerator lists supported table style element types. The Table object provides the following properties to optionally specify table elements to be formatted as defined by the corresponding elements of the applied table style.

Property Description
Table.ShowHeaders Displays the header row in the table and formats it as specified by the TableStyleElementType.HeaderRow element of the applied table style.
Table.ShowTotals Display the total row in the table and formats it as specified by the TableStyleElementType.TotalRow element of the applied table style.
Table.ShowTableStyleRowStripes Applies striped row formatting to a table as specified by the TableStyleElementType.FirstRowStripe and TableStyleElementType.SecondRowStripe elements of the applied table style.
Table.ShowTableStyleColumnStripes applies striped column formatting to a table as specified by the TableStyleElementType.FirstColumnStripe and TableStyleElementType.SecondColumnStripe elements of the applied table style.
Table.ShowTableStyleFirstColumn Formats the first column of the table as specified by the TableStyleElementType.FirstColumn, TableStyleElementType.FirstHeaderCell and TableStyleElementType.FirstTotalCell elements of the applied table style.
Table.ShowTableStyleLastColumn Formats the last column of the table as specified by the TableStyleElementType.LastColumn, TableStyleElementType.LastHeaderCell and TableStyleElementType.LastTotalCell elements of the applied table style.

This example demonstrates how to access a table style by its name and apply it to an existing table. The Table.ShowHeaders and Table.ShowTotals properties are set to true to show the header and total row of the table.

The Table.ShowTableStyleRowStripes and Table.ShowTableStyleColumnStripes properties are used to apply the striped column formatting to the table.

Private Sub ApplyBuiltInTableStyle(ByVal workbook As IWorkbook, ByVal table As Table, ByVal styleName As String)
    ' Access the workbook's collection of table styles.
    Dim tableStyles As TableStyleCollection = workbook.TableStyles

    ' Access the built-in table style from the collection by its name.
    Dim tableStyle As TableStyle = tableStyles(styleName)

    ' Apply the table style to the existing table.
    table.Style = tableStyle

    ' Show header and total rows.
    table.ShowHeaders = True
    table.ShowTotals = True

    ' Apply banded column formatting to the table.
    table.ShowTableStyleRowStripes = False
    table.ShowTableStyleColumnStripes = True
End Sub
See Also