DefinedName.destinations breaks when refers to table reference
🐛 Description of the bug
When Excel named range refers to a table reference, e.g. =my_table[#All]
, DefinedName.destinations
fails to parse the sheet and cells from the value.
Traceback
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\jonathan.biemond\.virtualenvs\venv\lib\site-packages\openpyxl\workbook\defined_name.py", line 140, in destinations
sheetname = m.group('notquoted') or m.group('quoted')
AttributeError: 'NoneType' object has no attribute 'group'
openpyxl version: 3.0.10
To reproduce
- Format a range as a table in Excel.
- Create a new named reference that refers to the table. Refers to should look like:
=<TABLE>[#All]
- Read WB with
openpyxl
and calldestinations
on the table reference DefinedName
Proposed solution
Firstly I will delete that name from my Workbook, I don't see a good reason for it to exist at all. I don't think it's reasonable to expect coordinates to be returned from this sort of reference. I do think it would be helpful if the value is validated and a descriptive error is raise when the regex doesn't match. Something like: InvalidRangeError: DefinedName '{name}' must refer to a valid range '{value}'
Edited by Jonathan Biemond