Skip to main content
All docs
V19.1
.NET Framework 4.5.2+
Row

PivotTableCollection.Add(PivotCache, Range) Method

Creates a new pivot table with the default name using the specified data cache and returns the newly created PivotTable object.

Namespace: DevExpress.Spreadsheet

Assembly: DevExpress.Spreadsheet.v19.1.Core.dll

Declaration

PivotTable Add(
    PivotCache cache,
    Range location
)

Parameters

Name Type Description
cache PivotCache

A PivotCache object that specifies the pivot cache on which the pivot table is based.

location Range

A Range object that specifies a cell or cell range in the upper-left corner of the PivotTable report’s destination range.

Returns

Type Description
PivotTable

A PivotTable object that specifies the newly created pivot table.

Remarks

The following example demonstrates how to use the Add method to create a new pivot table based on the PivotCache of the existing PivotTable report.

Dim worksheet As Worksheet = workbook.Worksheets.Add()
workbook.Worksheets.ActiveWorksheet = worksheet

' Create a pivot table based on the specified PivotTable cache.
Dim cache As PivotCache = workbook.Worksheets("Report1").PivotTables("PivotTable1").Cache
Dim pivotTable As PivotTable = worksheet.PivotTables.Add(cache, worksheet("B2"))

' Add the "Category" field to the row axis area.
pivotTable.RowFields.Add(pivotTable.Fields("Category"))
' Add the "Product" field to the row axis area.
pivotTable.RowFields.Add(pivotTable.Fields("Product"))
' Add the "Sales" field to the data area.
pivotTable.DataFields.Add(pivotTable.Fields("Sales"))

' Set the default style for the pivot table.
pivotTable.Style = workbook.TableStyles.DefaultPivotStyle

The following code snippets (auto-collected from DevExpress Examples) contain references to the Add(PivotCache, Range) 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.

See Also