Skip to main content
Row

PivotTableCollection.Add(PivotCache, CellRange) 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.v24.2.Core.dll

NuGet Package: DevExpress.Spreadsheet.Core

Declaration

PivotTable Add(
    PivotCache cache,
    CellRange location
)

Parameters

Name Type Description
cache PivotCache

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

location CellRange

A CellRange 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.

View Example

Worksheet worksheet = workbook.Worksheets.Add();
workbook.Worksheets.ActiveWorksheet = worksheet;

// Create a pivot table based on the specified PivotTable cache.
PivotCache cache = workbook.Worksheets["Report1"].PivotTables["PivotTable1"].Cache;
PivotTable pivotTable = worksheet.PivotTables.Add(cache, worksheet["B2"]);

pivotTable.BeginUpdate();

// 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;

pivotTable.EndUpdate();

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