Cannot open xlsx sheets

Issue #881 invalid
CK
created an issue

A have a bunch of excel sheets which I cannot open. The reason seems to be that the page margins are set to empty strings.

<pageMargins left="" right="" top="" bottom="" header="" footer=""/>

The sheets open fine with any version of ms-excel or openoffice.

This creates the following exception:

In [2]: wb = load_workbook(filename = 'new.xlsx')

ValueError Traceback (most recent call last) ~/.virtualenvs/hr-report/lib/python3.5/site-packages/openpyxl/descriptors/base.py in _convert(expected_type, value) 56 try: ---> 57 value = expected_type(value) 58 except:

ValueError: could not convert string to float:

During handling of the above exception, another exception occurred:

TypeError Traceback (most recent call last) <ipython-input-2-ae8ca938bfb5> in <module>() ----> 1 wb = load_workbook(filename = 'new.xlsx')

~/.virtualenvs/hr-report/lib/python3.5/site-packages/openpyxl/reader/excel.py in load_workbook(filename, read_only, keep_vba, data_only, guess_types, keep_links) 243 ws._rels = rels 244 ws_parser = WorkSheetParser(ws, fh, shared_strings) --> 245 ws_parser.parse() 246 247 if rels:

~/.virtualenvs/hr-report/lib/python3.5/site-packages/openpyxl/reader/worksheet.py in parse(self) 127 elif tag_name in properties: 128 prop = properties[tag_name] --> 129 obj = prop[1].from_tree(element) 130 setattr(self.ws, prop[0], obj) 131 element.clear()

~/.virtualenvs/hr-report/lib/python3.5/site-packages/openpyxl/descriptors/serialisable.py in from_tree(cls, node) 90 attrib[tag] = obj 91 ---> 92 return cls(**attrib) 93 94

~/.virtualenvs/hr-report/lib/python3.5/site-packages/openpyxl/worksheet/page.py in init(self, left, right, top, bottom, header, footer) 162 self.left = left 163 self.right = right --> 164 self.top = top 165 self.bottom = bottom 166 self.header = header

~/.virtualenvs/hr-report/lib/python3.5/site-packages/openpyxl/descriptors/base.py in set(self, instance, value) 67 if ((self.allow_none and value is not None) 68 or not self.allow_none): ---> 69 value = _convert(self.expected_type, value) 70 super(Convertible, self).set(instance, value) 71

~/.virtualenvs/hr-report/lib/python3.5/site-packages/openpyxl/descriptors/base.py in _convert(expected_type, value) 57 value = expected_type(value) 58 except: ---> 59 raise TypeError('expected ' + str(expected_type)) 60 return value 61

TypeError: expected <class 'float'>

Comments (6)

  1. CK reporter

    If you are implementing against the OOXML spec that is fine with me. I figured out xlrd can open the files as well. So I will be using xlrd.

  2. Log in to comment