Back to Devexpress

PivotTableCollection Interface

officefileapi-devexpress-dot-spreadsheet-abc399e6.md

latest4.0 KB
Original Source

PivotTableCollection Interface

A collection of all PivotTable objects in the worksheet.

Namespace : DevExpress.Spreadsheet

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

NuGet Package : DevExpress.Spreadsheet.Core

Declaration

csharp
public interface PivotTableCollection :
    ISimpleCollection<PivotTable>,
    IEnumerable<PivotTable>,
    IEnumerable,
    ICollection
vb
Public Interface PivotTableCollection
    Inherits ISimpleCollection(Of PivotTable),
             IEnumerable(Of PivotTable),
             IEnumerable,
             ICollection

The following members return PivotTableCollection objects:

Remarks

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.

Example

View Example

vb
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"))
csharp
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

PivotTableCollection Members

Pivot Tables in Spreadsheet Documents

Pivot Table Structure

WinForms Spreadsheet Control Examples

DevExpress.Spreadsheet Namespace