Back to Devexpress

TableStyle.Duplicate() Method

officefileapi-devexpress-dot-spreadsheet-dot-tablestyle-df643c37.md

latest4.6 KB
Original Source

TableStyle.Duplicate() Method

Creates a copy of this table or PivotTable style.

Namespace : DevExpress.Spreadsheet

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

NuGet Package : DevExpress.Spreadsheet.Core

Declaration

csharp
TableStyle Duplicate()
vb
Function Duplicate As TableStyle

Returns

TypeDescription
TableStyle

A copy of the current style.

|

Remarks

You can create a custom style based on an existing table or PivotTable style (for example, a built-in style). Call the TableStyle.Duplicate method to create a copy of the specified style. This method returns a TableStyle object that allows you to define format settings for the new style.

Example

The code snippet below creates a copy of a predefined table style and changes the header row color for the new style.

View Example: Create and Format Spreadsheet Tables

csharp
// Access worksheet tables.
Table table1 = worksheet.Tables[0];
Table table2 = worksheet.Tables[1];

// Return a table style you want to duplicate.
TableStyle sourceTableStyle = workbook.TableStyles[BuiltInTableStyleId.TableStyleMedium17];

// Duplicate the table style.
TableStyle newTableStyle = sourceTableStyle.Duplicate();

// Modify the new table style.
// Change background color for the header row.
newTableStyle.TableStyleElements[TableStyleElementType.HeaderRow].Fill.BackgroundColor = Color.FromArgb(0xA7, 0xEA, 0x52);

table1.Style = sourceTableStyle;
table2.Style = newTableStyle;
vb
' Access worksheet tables.
Dim table1 As Table = worksheet.Tables(0)
Dim table2 As Table = worksheet.Tables(1)

' Return a table style you want to duplicate.
Dim sourceTableStyle As TableStyle = workbook.TableStyles(BuiltInTableStyleId.TableStyleMedium17)

' Duplicate the table style.
Dim newTableStyle As TableStyle = sourceTableStyle.Duplicate()

' Modify the new table style.
' Change background color for the header row.
newTableStyle.TableStyleElements(TableStyleElementType.HeaderRow).Fill.BackgroundColor = Color.FromArgb(&HA7, &HEA, &H52)

table1.Style = sourceTableStyle
table2.Style = newTableStyle

The image below shows the built-in TableStyleMedium17 style and its modified copy (the workbook is opened in Microsoft® Excel®).

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the Duplicate() method.

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-part2/CS/SpreadsheetDocServerAPIPart2/CodeExamples/TableActions.cs#L187

csharp
// Duplicate the table style.
TableStyle newTableStyle = sourceTableStyle.Duplicate();

spreadsheet-document-api-examples-part2/VB/SpreadsheetDocServerAPIPart2/CodeExamples/TableActions.vb#L174

vb
' Duplicate the table style.
Dim newTableStyle As TableStyle = sourceTableStyle.Duplicate()

See Also

TableStyle Interface

TableStyle Members

DevExpress.Spreadsheet Namespace