In this step-by-step tutorial, an explanation is provided on how to remove pivot table in Excel in C#. Detailed information is provided to set the development environment, a list of tasks for writing the application, and a ready-to-run code that demonstrates how to remove the pivot table in Excel in C#. This code can be executed in any of the platforms supporting the .NET environment and does not require any other tool or software to delete one or more pivot tables from an Excel file.
Steps to Remove Pivot Table in C#
- Using the NuGet package manager, add Aspose.Cells for .NET to the project to delete pivot tables
- Load the workbook
- Access the worksheet
- Access the pivot table from the worksheet
- Remove the pivot table
- Save the workbook
The above steps have described how to delete pivot table in Excel in C#. The process is commenced by loading the workbook followed by accessing the target worksheet. Each worksheet has a PivotTableCollection class object that exposes the Remove() method that is used to perform this task in the sample code. In the end, the output workbook can be saved in any of the supported formats having all the data except the removed pivot table.
Code to Delete Pivot Table in C#
This sample code has demonstrated how to remove pivot table in C#. It uses the Remove() method that requires a pivot table object for removing it from the collection. However, if you know the target pivot table index in the collection, you may use RemoveAt() method that requires the index number only.
In this quick guide, we have learned how to delete pivot table in C#. If you are inclined to learn the process to generate a new pivot table, refer to the article on how to create pivot table in Excel using C#.