Python – openpyxl error: got an unexpected keyword argument ‘quotePrefix’

openpyxl, python

I've written a script that reads an .xlsx file using openpyxl on MacOS.
I made updates to allow my script to run on MacOS or Linux. Openpyxl is raising an error when calling load_workbook.

import platformsystem = platform.system()if system == "Darwin":    cpgatt = "/Users/tlombard/desktop/py-sandbox/PickleJar/CSG_CHG_Clarity_attributes1.xlsx"if system == 'Linux':    cpgatt = "/ws/tlombard-sjc/Picklejar/CSG_CHG_Clarity_attributes1.xlsx"cpgatt_wb = openpyxl.load_workbook(cpgatt)

The error I get is:

"TypeError: __init__() got an unexpected keyword argument 'quotePrefix'"The full traceback:-------Traceback (most recent call last):  File "<stdin>", line 1, in <module>  File "/auto/elb_hwtools/cae/lib/python/v2.7.8/openpyxl/reader/excel.py", line 149, in load_workbook    _load_workbook(wb, archive, filename, read_only, keep_vba)  File "/auto/elb_hwtools/cae/lib/python/v2.7.8/openpyxl/reader/excel.py", line 237, in _load_workbook    keep_vba=keep_vba)  File "/auto/elb_hwtools/cae/lib/python/v2.7.8/openpyxl/reader/worksheet.py", line 324, in read_worksheet    fast_parse(ws, xml_source, shared_strings, style_table, color_index)  File "/auto/elb_hwtools/cae/lib/python/v2.7.8/openpyxl/reader/worksheet.py", line 312, in fast_parse    parser.parse()  File "/auto/elb_hwtools/cae/lib/python/v2.7.8/openpyxl/reader/worksheet.py", line 93, in parse    dispatcher[tag_name](element)  File "/auto/elb_hwtools/cae/lib/python/v2.7.8/openpyxl/reader/worksheet.py", line 189, in parse_row_dimensions    self.parse_cell(cell)  File "/auto/elb_hwtools/cae/lib/python/v2.7.8/openpyxl/reader/worksheet.py", line 134, in parse_cell    cell = Cell(self.ws, column, row, **style)TypeError: __init__() got an unexpected keyword argument 'quotePrefix'>>> cpgatt'/ws/tlombard-sjc/Picklejar/CSG_CHG_Clarity_attributes1.xlsx'>>> 

Best Solution

I had the same problem, here is my full trace:

Traceback (most recent call last):  File "__init__.py", line 318, in readExcelFile    wb2 = load_workbook( unicode(self.ui_sourcePath.text()))#self.ui_sourcePath.text().replace("/",  "\\"))  File "C:\Python27\lib\site-packages\openpyxl\reader\excel.py", line 149, in load_workbook    _load_workbook(wb, archive, filename, read_only, keep_vba)  File "C:\Python27\lib\site-packages\openpyxl\reader\excel.py", line 237, in _load_workbook    keep_vba=keep_vba)  File "C:\Python27\lib\site-packages\openpyxl\reader\worksheet.py", line 325, in read_worksheet    fast_parse(ws, xml_source, shared_strings, style_table, color_index)  File "C:\Python27\lib\site-packages\openpyxl\reader\worksheet.py", line 313, in fast_parse    parser.parse()  File "C:\Python27\lib\site-packages\openpyxl\reader\worksheet.py", line 93, in parse    dispatcher[tag_name](element)  File "C:\Python27\lib\site-packages\openpyxl\reader\worksheet.py", line 190, in parse_row_dimensions    self.parse_cell(cell)  File "C:\Python27\lib\site-packages\openpyxl\reader\worksheet.py", line 135, in parse_cell    cell = Cell(self.ws, column, row, **style)TypeError: __init__() got an unexpected keyword argument 'quotePrefix'

As you can see in the trace, the error is occuring when openpyxl tries to parse the workbook. I added the following line in C:\Python27\lib\site-packages\openpyxl\reader\worksheet.py @135

column, row = coordinate_from_string(coordinate)print column,  rowcell = Cell(self.ws, column, row, **style)

The problem came from one of the cell in my Excel workbook, and only one. My temporary solution to this problem is to delete de quotePrefix key in the style dict:

    style = {}    if style_id is not None:        style_id = int(style_id)        style = self.styles[style_id]        if "quotePrefix" in style.keys():                del style["quotePrefix"]    column, row = coordinate_from_string(coordinate)    cell = Cell(self.ws, column, row, **style)    self.ws._add_cell(cell)

I couldn't manage to find why this particular cell cause these problems and how to override a quote prefix.