officefileapi-devexpress-dot-spreadsheet-abc399e6.md
A collection of all PivotTable objects in the worksheet.
Namespace : DevExpress.Spreadsheet
Assembly : DevExpress.Spreadsheet.v25.2.Core.dll
NuGet Package : DevExpress.Spreadsheet.Core
public interface PivotTableCollection :
ISimpleCollection<PivotTable>,
IEnumerable<PivotTable>,
IEnumerable,
ICollection
Public Interface PivotTableCollection
Inherits ISimpleCollection(Of PivotTable),
IEnumerable(Of PivotTable),
IEnumerable,
ICollection
The following members return PivotTableCollection objects:
Use the Worksheet.PivotTables property to get access to the PivotTableCollection collection. An individual PivotTable can be accessed by its name or index in the collection.
To create a new pivot table, use the PivotTableCollection.Add method. You can base your pivot table on a cell range or a PivotCache of the existing report.
To remove a specific pivot table from the collection, use the PivotTableCollection.Remove or PivotTableCollection.RemoveAt method.
Dim sourceWorksheet As Worksheet = workbook.Worksheets("Data1")
Dim worksheet As Worksheet = workbook.Worksheets.Add()
workbook.Worksheets.ActiveWorksheet = worksheet
' Create a pivot table using the cell range "A1:D41" as the data source.
Dim pivotTable As PivotTable = worksheet.PivotTables.Add(sourceWorksheet("A1:D41"), 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"))
Worksheet sourceWorksheet = workbook.Worksheets["Data1"];
Worksheet worksheet = workbook.Worksheets.Add();
workbook.Worksheets.ActiveWorksheet = worksheet;
// Create a pivot table using the cell range "A1:D41" as the data source.
PivotTable pivotTable = worksheet.PivotTables.Add(sourceWorksheet["A1:D41"], 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"]);
See Also
Pivot Tables in Spreadsheet Documents