Workbook fails on empty cells.
Created originally on Bitbucket by Anonymous
Kept getting the following bug:
{{{ #!python
In [4]: load_workbook('faculty360.xlsx')
TypeError Traceback (most recent call last)
in ()
/usr/local/lib/python2.6/dist-packages/openpyxl-1.5.8-py2.6.egg/openpyxl/reader/excel.pyc in load_workbook(filename, use_iterators) 93 94 try: ---> 95 _load_workbook(wb, archive, filename, use_iterators) 96 except KeyError, e: 97 raise InvalidFileException(unicode(e))
/usr/local/lib/python2.6/dist-packages/openpyxl-1.5.8-py2.6.egg/openpyxl/reader/excel.pyc in _load_workbook(wb, archive, filename, use_iterators) 134 xml_source = unpack_worksheet(archive, worksheet_path) 135 new_ws = read_worksheet(xml_source, wb, sheet_name, string_table, style_table, filename, sheet_codename) 136 wb.add_sheet(new_ws, index=i) 137 --> 138 wb._named_ranges = read_named_ranges(archive.read(ARC_WORKBOOK), wb)
/usr/local/lib/python2.6/dist-packages/openpyxl-1.5.8-py2.6.egg/openpyxl/reader/workbook.pyc in read_named_ranges(xml_source, workbook) 115 116 for bad_range in BUGGY_NAMED_RANGES: --> 117 if bad_range in name_node.text: 118 valid = False 119
TypeError: argument of type 'NoneType' is not iterable
}}}
This had a very quick fix of changing line 117 of /usr/local/lib/python2.6/dist-packages/openpyxl-1.5.8-py2.6.egg/openpyxl/reader/workbook.py to:
{{{ if hasattr(name_node, 'text') or bad_range in name_node.text: }}}
and then the xlsx reader loads with no issues. I can't share the particular file that was causing the error (and not sure how my colleague generated it).