6

I am using openpyxl library to read .xlsx files in Python. I need to read some information (title, series names etc) about charts embedded in worksheets. Documentation mentions only creating new charts, and reading existing charts is nowhere mentioned.

#!/usr/bin/env python

from openpyxl import load_workbook
wb = load_workbook("charts.xlsx")
for sheet in wb:
    # wb.???
1
  • Can you share your xlsx sample? Commented Feb 7, 2019 at 16:17

2 Answers 2

4

Unfortunately the current version of OpenPyXL does not allow to load charts from Excel files. If you load a Workbook and immediately save it to the same filename you will effectively remove the charts from it.

Sign up to request clarification or add additional context in comments.

2 Comments

As I noticed (Python 3.8.5), already created charts are not being removed when I save the file. But I can't access an already created chart object from Python (still looking for a way).
Did you find the solution? I am facing with the same issue and my ownly workaround is using pywin32 library (which doesn't work for linux obviously) provided here - stackoverflow.com/a/68173137/8139118
1

Refering to the chart class in openpyxl you can retrieve info like chart title, legends, table references etc.:

from openpyxl import load_workbook
wb = load_workbook("charts.xlsx")

sheetnames = wb.sheetnames
charts = []

for sheet in sheetnames:
    ws = wb[sheet]
    chart_info = ws._charts
    charts.append(chart_info)

1 Comment

Refering to the chart class in openpyxl you can retrieve info like chart title, legends, table references etc.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.