officefileapi-devexpress-dot-spreadsheet-dot-pivottablecollection-dot-add-x28-devexpress-dot-spreadsheet-dot-pivotcache-devexpress-dot-spreadsheet-dot-cellrange-x29.md
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.v25.2.Core.dll
NuGet Package : DevExpress.Spreadsheet.Core
PivotTable Add(
PivotCache cache,
CellRange location
)
Function Add(
cache As PivotCache,
location As CellRange
) As PivotTable
| 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.
|
| Type | Description |
|---|---|
| PivotTable |
A PivotTable object that specifies the newly created pivot table.
|
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.
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();
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"))
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.BeginUpdate()
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.
PivotCache cache = workbook.Worksheets["Report1"].PivotTables["PivotTable1"].Cache;
PivotTable pivotTable = worksheet.PivotTables.Add(cache, worksheet["B2"]);
PivotCache cache = workbook.Worksheets["Report1"].PivotTables["PivotTable1"].Cache;
PivotTable pivotTable = worksheet.PivotTables.Add(cache, worksheet["B2"]);
PivotCache cache = workbook.Worksheets["Report1"].PivotTables["PivotTable1"].Cache;
PivotTable pivotTable = worksheet.PivotTables.Add(cache, worksheet["B2"]);
Dim cache As PivotCache = workbook.Worksheets("Report1").PivotTables("PivotTable1").Cache
Dim pivotTable As PivotTable = worksheet.PivotTables.Add(cache, worksheet("B2"))
Dim cache As PivotCache = workbook.Worksheets("Report1").PivotTables("PivotTable1").Cache
Dim pivotTable As PivotTable = worksheet.PivotTables.Add(cache, worksheet("B2"))
Dim cache As PivotCache = workbook.Worksheets("Report1").PivotTables("PivotTable1").Cache
Dim pivotTable As PivotTable = worksheet.PivotTables.Add(cache, worksheet("B2"))
See Also