PivotTable.MoveTo(CellRange) Method
Moves a pivot table to the specified location.
Namespace: DevExpress.Spreadsheet
Assembly: DevExpress.Spreadsheet.v24.1.Core.dll
NuGet Package: DevExpress.Spreadsheet.Core
Declaration
Parameters
Name | Type | Description |
---|---|---|
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 represents the moved pivot table. |
Remarks
The MoveTo method returns one of the following values depending on the report target location:
- A reference to the current PivotTable object if the pivot table is moved to a new location in the same worksheet.
- A reference to a new PivotTable object if the pivot table is moved to another worksheet. This operation removes the pivot table from the collection of pivot tables in the source worksheet and appends it to the PivotTableCollection collection of the target worksheet. Correspondingly, a reference to the PivotTable object in the source worksheet becomes invalid. If you try to use it in your application, a System.InvalidOperationException will be thrown.
The example below demonstrates how to move a pivot table to another worksheet in a workbook.
Worksheet worksheet = workbook.Worksheets["Report1"];
// Create a new worksheet.
Worksheet targetWorksheet = workbook.Worksheets.Add();
// Access the pivot table by its name in the collection
// and move it to the new worksheet.
worksheet.PivotTables["PivotTable1"].MoveTo(targetWorksheet["B2"]);
// Refresh the pivot table.
targetWorksheet.PivotTables["PivotTable1"].Cache.Refresh();
workbook.Worksheets.ActiveWorksheet = targetWorksheet;
Related GitHub Examples
The following code snippets (auto-collected from DevExpress Examples) contain references to the MoveTo(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.