Read values from named ranges with openpyxl

Jamgreen picture Jamgreen · Mar 6, 2015 · Viewed 11.4k times · Source

How can I read values from named ranges in Excel with openpyxl?

I've found the sourcecode at http://openpyxl.readthedocs.org/en/latest/_modules/openpyxl/workbook/names/named_range.html but I can't figure out how to use it properly.

Answer

Chad picture Chad · Mar 27, 2015
wb = openpyxl.load_workbook(excel_file_name) 
rng = wb.get_named_range(name_of_range).destinations[0]
sheet = rng[0]
address = rng[1].replace('$','')
val = sheet[address].value