Back to Devexpress

PivotTable.Clear() Method

officefileapi-devexpress-dot-spreadsheet-dot-pivottable-eac75a49.md

latest5.4 KB
Original Source

PivotTable.Clear() Method

Removes all fields, formatting and report filters from the PivotTable report.

Namespace : DevExpress.Spreadsheet

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

NuGet Package : DevExpress.Spreadsheet.Core

Declaration

csharp
void Clear()
vb
Sub Clear

Remarks

The Clear method does not delete the pivot table, but resets it to the initial state, before any fields were added to it. The data connection, PivotTable cache and the report location are preserved.

To completely delete the PivotTable report from the worksheet, remove it from the worksheet’s PivotTableCollection by using the PivotTableCollection.Remove method.

Important

If the pivot table you wish to clear is based on the same data as other pivot tables in a document, the Clear method will also remove grouping, calculated fields, and calculated items from other shared PivotTable reports.

Example

View Example

csharp
Worksheet worksheet = workbook.Worksheets["Report1"];
workbook.Worksheets.ActiveWorksheet = worksheet;

// Clear the pivot table.
worksheet.PivotTables["PivotTable1"].Clear();
vb
Dim worksheet As Worksheet = workbook.Worksheets("Report1")
workbook.Worksheets.ActiveWorksheet = worksheet

' Clear the pivot table.
worksheet.PivotTables("PivotTable1").Clear()

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

wpf-spreadsheet-pivot-table-api-examples/CS/SpreadsheetWPFPivotTableExamples/CodeExamples/PivotTableActions.cs#L129

csharp
// Clear the pivot table.
worksheet.PivotTables["PivotTable1"].Clear();
#endregion #ClearTable

winforms-spreadsheet-pivot-table-api/CS/SpreadsheetPivotTableExamples/CodeExamples/PivotTableActions.cs#L123

csharp
// Clear the pivot table.
worksheet.PivotTables["PivotTable1"].Clear();
#endregion #ClearTable

spreadsheet-document-api-pivot-table-examples/CS/SpreadsheetDocServerPivotAPI/CodeExamples/PivotTableActions.cs#L133

csharp
// Clear the pivot table.
worksheet.PivotTables["PivotTable1"].Clear();
#endregion #ClearTable

wpf-spreadsheet-pivot-table-api-examples/VB/SpreadsheetWPFPivotTableExamples/CodeExamples/PivotTableActions.vb#L124

vb
' Clear the pivot table.
            worksheet.PivotTables("PivotTable1").Clear()
' #End Region ' #ClearTable

winforms-spreadsheet-pivot-table-api/VB/SpreadsheetPivotTableExamples/CodeExamples/PivotTableActions.vb#L118

vb
' Clear the pivot table.
            worksheet.PivotTables("PivotTable1").Clear()
' #End Region ' #ClearTable

spreadsheet-document-api-pivot-table-examples/VB/SpreadsheetDocServerPivotAPI/CodeExamples/PivotTableActions.vb#L121

vb
' Clear the pivot table.
            worksheet.PivotTables("PivotTable1").Clear()
#End Region ' #ClearTable

See Also

Remove(PivotTable)

PivotTable Interface

PivotTable Members

DevExpress.Spreadsheet Namespace