Last active
July 16, 2023 16:51
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/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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