5

I just created a script with openpyxl to update a xlsx file that we usually update manually every month.

It work fine, but the new file lost all the graphs and images that were in the workbook. Is there a way to keep them?

Daniel Pereira
  • 167
  • 3
  • 12
  • The normal answer here, if you really need to keep existing content and you are on a platform that has Excel on it, is to use a scripting language to control Excel itself, rather than manipulating the files directly. Personally, I think it's simple enough to use VBA or VBScript, but if you want to stick with Python, give [xlwings](https://pypi.python.org/pypi/xlwings) a try. – John Y May 13 '16 at 21:52

2 Answers2

5

openpyxl version 2.5 will preserve charts in existing files.

Charlie Clark
  • 18,477
  • 4
  • 49
  • 55
  • Hi Charlie thanks for your response. Is there any way to preserve check box and dropdowns? Using Openpyxl . – Saurabh Agrawal Feb 25 '19 at 10:10
  • @Charlie Clark I have a sheet where I update chart data range every two months. But now since the new version of openpyxl preserves previous charts, whenever I create a chart using updated data range, it overlays the previous chart in the sheet. Is there a way to delete the previous chart or just update the data range of existing chart? – Parth Karia Dec 22 '19 at 10:51
0

Use xlwings instead, it works as a wrapper on pywin32 and can preserve the existing Excel graphs, pivot-tables, etc.

Ronan Boiteau
  • 9,608
  • 6
  • 34
  • 56
Rishil Antony
  • 725
  • 5
  • 5