How To Refresh Pivot Tables Using OpenPyXL?

Method

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

dt[‘F2′]=’China’    #Modify Data Source

#Refresh Pivot Table

pivot.cache.refreshOnLoad=True

Sample Code

#Refresh Pivot Table

from openpyxl import load_workbook

#Load Workbook
wb=load_workbook('Pivot.xlsx')
dt=wb['Data Source']
ws=wb['Pivot Table']

pivot=ws._pivots[0]    #Reference the 1st Pivot Table
dt['F2']='China'    #Modify Data Source
#Refresh Pivot Table
pivot.cache.refreshOnLoad=True

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

Leave a Reply

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