How To Reference Pivot Tables Using OpenPyXL?

Method

pivot=ws._pivots[0]    #Reference the 1st Pivot Table

print(pivot.name)    #Name of the Pivot Table

Sample Code

#Reference Pivot Table

from openpyxl import load_workbook

#Load Workbook
wb=load_workbook('Pivot.xlsx')
#Get Worksheet
ws=wb['Pivot Table']

pivot=ws._pivots[0]    #Reference the 1st Pivot Table
print(pivot.name)    #Name of the Pivot Table

#Pivot Table Overview
print(pivot.summary)

wb.save('test.xlsx')
Reference Pivot Tables Using OpenPyXL

Leave a Reply

Your email address will not be published. Required fields are marked *