loading a workbook fail when PrintTitles is NoneType
--- Logging error ---
Traceback (most recent call last):
File "d:\...\app\controller\functions.py", line 135, in excel2sqlite
wb = openpyxl.load_workbook(filename=path, data_only=True)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\...\Python\Python311\site-packages\openpyxl\reader\excel.py", line 346, in load_workbook
reader.read()
File "C:\...\Python\Python311\site-packages\openpyxl\reader\excel.py", line 303, in read
self.parser.assign_names()
File "C:\...\Python\Python311\site-packages\openpyxl\reader\workbook.py", line 111, in assign_names
titles = PrintTitles.from_string(defn.value)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\...\Python\Python311\site-packages\openpyxl\worksheet\print_settings.py", line 133, in from_string
return cls(cols=cols, rows=rows, title=title)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\...\Python\Python311\site-packages\openpyxl\worksheet\print_settings.py", line 112, in __init__
self.title = title
^^^^^^^^^^
File "C:\...\Python\Python311\site-packages\openpyxl\descriptors\base.py", line 46, in __set__
raise TypeError(msg)
TypeError: <class 'openpyxl.worksheet.print_settings.PrintTitles'>.title should be <class 'str'> but value is <class 'NoneType'>
I added an if condition to the method PrintTitles.from_string and it worked:
@classmethod
def from_string(cls, value):
kw = dict((k, v) for match in TITLES_REGEX.finditer(value)
for k, v in match.groupdict().items() if v)
if not kw:
raise ValueError(f"{value} is not a valid print titles definition")
cols = rows = None
if "cols" in kw:
cols = ColRange(kw["cols"])
if "rows" in kw:
rows = RowRange(kw["rows"])
title = kw.get("quoted") or kw.get("notquoted")
title = title if title is not None else ""
return cls(cols=cols, rows=rows, title=title)