Skip to content

Instantly share code, notes, and snippets.

How to Delete Pivot Table in Excel using Python. For more details: https://kb.aspose.com/cells/python/how-to-delete-pivot-table-in-excel-using-python/
import jpype
import asposecells
jpype.startJVM()
from asposecells.api import License, Workbook
# Instantiate the license
license = License()
license.setLicense("Aspose.Total.lic")
# Create a workbook object from the source Excel file
workbook = Workbook("pivotTable.xls")
# Access the first worksheet
worksheet = workbook.getWorksheets().get(0)
# Access the first pivot table object
pivotTable = worksheet.getPivotTables().get(0)
# Remove the pivot table using the pivot table object
worksheet.getPivotTables().remove(pivotTable)
# Second option is to delete the pivot table using its index
# worksheet.getPivotTables().removeAt(0);
# Save the workbook
workbook.save("output_out.xlsx")
print("Pivot Table removed successfully")
jpype.shutdownJVM()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment