Missing column width causes load_workbook() exception

Issue #300 resolved
Mark Brighton
created an issue

I've encountered an exception (traceback below) when trying to open an xlsx file that was created by Google docs (attached trivial sample). It appears that some of the column elements don't have a width attribute. This causes ColumnDimensions.init() to throw a type error when it tries to call float(None)

It seems like the simple solution is to change that line to catch the exception and set width to -1 (the default in the method signature).

This exception happens when load_workbook() is called with use_iterators=False (the default). If it's called with use_iterators=True, then only a warning is emitted.

I'm using Python 2.7.6 and openpyxl 1.8.5.


Traceback (most recent call last): File "C:\Python27\Lib\site-packages\Pythonwin\pywin\framework\scriptutils.py", line 326, in RunScript exec codeObject in main.dict File "C:\Documents and Settings\On-Cue User\My Documents\Imorgon\py_dicom\seleiumGenerator.py", line 199, in <module> main(args.path, args.scriptPath, args.sheet, args.ipAddress or '') File "C:\Documents and Settings\On-Cue User\My Documents\Imorgon\py_dicom\seleiumGenerator.py", line 128, in main wb = openpyxl.load_workbook(excelFilename, False) File "C:\Python27\lib\site-packages\openpyxl\reader\excel.py", line 136, in load_workbook _load_workbook(wb, archive, filename, use_iterators, keep_vba) File "C:\Python27\lib\site-packages\openpyxl\reader\excel.py", line 198, in _load_workbook keep_vba=keep_vba) File "C:\Python27\lib\site-packages\openpyxl\reader\worksheet.py", line 332, in read_worksheet fast_parse(ws, xml_source, string_table, style_table, color_index) File "C:\Python27\lib\site-packages\openpyxl\reader\worksheet.py", line 320, in fast_parse parser.parse() File "C:\Python27\lib\site-packages\openpyxl\reader\worksheet.py", line 137, in parse dispatchertag_name File "C:\Python27\lib\site-packages\openpyxl\reader\worksheet.py", line 198, in parse_column_dimensions collapsed=collapsed, style_index=style_index) File "C:\Python27\lib\site-packages\openpyxl\worksheet.py", line 345, in init self.width = float(width) TypeError: float() argument must be a string or a number

Comments (4)

  1. Log in to comment