workbook containing worksheet with space in name and print titles fails to open
Created originally on Bitbucket by JC (Jacob C)
Attempting to open a workbook that contains any worksheets with a space in the name and a print title will result in an error as below: (Python 3.5, Openpyxl 2.4)
#!python
Traceback (most recent call last):
File "C:/Users/user/pythonProjects/testproject/testpy/tester.py", line 5, in <module>
EngineerMetrics = ox.load_workbook("book1.xlsx", data_only=True, read_only=True)
File "C:\Users\user\AppData\Roaming\Python\Python35\site-packages\openpyxl\reader\excel.py", line 245, in load_workbook
parser.assign_names()
File "C:\Users\user\AppData\Roaming\Python\Python35\site-packages\openpyxl\packaging\workbook.py", line 79, in assign_names
rows, cols = _unpack_print_titles(defn)
File "C:\Users\user\AppData\Roaming\Python\Python35\site-packages\openpyxl\workbook\defined_name.py", line 48, in _unpack_print_titles
return m.group('rows'), m.group('cols')
AttributeError: 'NoneType' object has no attribute 'group'
It took a little bit to isolate, attached is a workbook that will demonstrate the issue.
With a workbook containing a "Sheet 1"
#!python
def _unpack_print_titles(defn):
"""
Extract rows and or columns from print titles so that they can be
assigned to a worksheet
"""
m = TITLES_REGEX.match(defn.value) # defn.value = '\\'Sheet 1\\'!$A:$A,\\'Sheet 1\\'!$1:$1'
return m.group('rows'), m.group('cols')
With a workbook containing Sheet1
#!python
def _unpack_print_titles(defn):
"""
Extract rows and or columns from print titles so that they can be
assigned to a worksheet
"""
m = TITLES_REGEX.match(defn.value) # defn.value = 'Sheet1!$A:$A,Sheet1!$1:$1'
return m.group('rows'), m.group('cols')
Attachments: Book1.xlsx