This concise tutorial explains how to delete pivot table in Excel using Python. It has the details to set the development environment, a list of programming steps to accomplish the task along with a sample code showing how to remove pivot table in Excel using Python. It explains different options to delete pivot tables available in a worksheet.
Steps to Remove Pivot Table using Python
- Set the development environment to use Aspose.Cells for Python via Java to delete pivot table
- Load the workbook having a few pivot tables in it
- Access the target worksheet having the pivot table
- Get the collection of pivot tables in the sheet and access the first pivot table
- Cell the remove method in the PivotTables collection
- Save the resultant workbook after deleting the pivot table
These steps summarize how to remove the pivot table in Excel using Python. The process is initiated by loading the workbook and accessing the target worksheet having the pivot table that is to be deleted followed by accessing the target pivot table from the pivot tables collection in the worksheet. In the final steps, the workbook is saved where the pivot table is removed, however, the source data remains there in the sheet.
Code to Delete Pivot Table using Python
This sample code demonstrates how to delete pivot table using Python. It uses the remove() method in the PivotTables collection that requires the reference to the target pivot table that is to be deleted. Use the removeAt() method in case you want to delete the pivot table based on its position.
This article has taught us to remove the pivot table from an Excel file. If you want to learn the process to add a pivot table to a worksheet, refer to the article on how to create pivot table in Python.