OpenPyXL broken pivot table refresh

Viewed 204

I'm on Python 3.9 and OpenPyXL 3.0.9.

So this is my current code basically having OpenPyXL refresh all of my pivot tables as soon as it opens. These pivot tables are pulling data from a different sheet in the workbook. So I'm basically putting in new data into the data sheet manually and want OpenPyXL to update/refresh the pivot tables.

This is my code:

from openpyxl import load_workbook
wb = load_workbook(r'file.xlsx')
psheet = wb["Pivot Table Sheet"]
pivot = psheet._pivots[0]
pivot.cache.refreshOnLoad = True

wb.save(r'file.xlsx')

So I input my data into the data sheet then run the code but I end up with a worksheet that is basically just text as strings and not formatted as a pivot table.

It gives me this error: enter image description here

I was wondering where I went wrong.

0 Answers
Related