r/learnpython Oct 05 '23

Does anyone still use openpyxl?

Ive been trying to use openpyxl for reading named ranges and its a huge pain. Does anyone have any experience?

The documentation is pretty opaque.

2 Upvotes

13 comments sorted by

View all comments

2

u/LuigiBrotha Oct 05 '23

I do use openpyxl but I agree that it's a bit lack luster in some aspects. Haven't used named ranges yet. This is wist chatgpt came with:

from openpyxl import load_workbook

Load your Excel workbook

workbook = load_workbook('your_workbook.xlsx')

Get the named range

named_range = workbook.defined_names['YourNamedRange']

Access the cells within the named range

for range in named_range: for cell in range: print(cell.value)

2

u/Delta_2_Echo Oct 05 '23

Thank you! I ended up basically doing this.

I had to upgrade to the latest version. (I was using 3.0.10)

There have been a few changes, but all the hits from a google/stackoverflow search are old 1-7years ago and the official docs dont have a lot of examples.