Search code examples
pythonexcelxlrd

xlrd error when opening Excel files with named ranges


I'm getting the following error message when attempting to open a workbook using xlrd 0.9.1 on Python 3.2.4. I tested to see what could be causing the issue and I've troubleshooted it to the spreadsheet having named ranges.

Traceback (most recent call last):
  File "C:\Users\mandroid\Desktop\xltest.py", line 5, in <module>
    book = open_workbook(pth)
  File "C:\Python32\lib\site-packages\xlrd\__init__.py", line 416, in open_workbook
    ragged_rows=ragged_rows,
  File "C:\Python32\lib\site-packages\xlrd\xlsx.py", line 725, in open_workbook_2007_xml
    x12book.process_stream(zflo, 'Workbook')
  File "C:\Python32\lib\site-packages\xlrd\xlsx.py", line 251, in process_stream
    meth(self, elem)
  File "C:\Python32\lib\site-packages\xlrd\xlsx.py", line 346, in do_defined_names
    self.do_defined_name(child)
  File "C:\Python32\lib\site-packages\xlrd\xlsx.py", line 335, in do_defined_name
    nobj.formula_text = cooked_text(self, elem)
  File "C:\Python32\lib\site-packages\xlrd\xlsx.py", line 130, in cooked_text
    return unicode(unescape(t))
TypeError: <lambda>() takes exactly 2 arguments (1 given)

From what I've read, it looks like xlrd has named range functionality, so I'm not sure what could be causing this. Any help is appreciated.


Solution

  • It's a bug in xlrd 0.9.1: https://github.com/python-excel/xlrd/issues/47

    You can try 0.9.0, wait for 0.9.2, or apply the fix John Machin suggests in the report.