Parth Karia
Parth Karia

Reputation: 315

Create Pivot Table using Openpyxl

Is there a way we can create pivot table in Excel using openpyxl library? I saw old threads mentioning its not possible, but I saw some documentation about creating one on below link:

https://openpyxl.readthedocs.io/en/2.5/api/openpyxl.pivot.table.html

Although I cant find any practical example of how to use the information provided in above link.

Upvotes: 7

Views: 19436

Answers (1)

Woodly0
Woodly0

Reputation: 434

It cannot be done. As mentioned already in the comments and also in the official docs, the pivot module of openpyxl is only there to preserve existing pivots.

I suggest you create a template.xlsx workbook with raw data on one sheet and your pivot table on another one. In the Excel pivot options, you activate refresh data when opening file. Then you use openpyxl to: Load this template, update the raw data and save it somewhere.

Excel will update the pivot table content when the file is opened the next time.

Upvotes: 11

Related Questions