unexpected keyword argument 'mergeCell' from load_workbook

Issue #463 resolved
Tim Smith
created an issue

python -c 'from openpyxl import load_workbook, __version__; print(__version__); load_workbook("May 22, 2015, Mouse Cytokine 31-Plex, Smith, Cell Culture.xlsx")' gives the following traceback:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/usr/local/lib/python2.7/site-packages/openpyxl/reader/excel.py", line 149, in load_workbook
    _load_workbook(wb, archive, filename, read_only, keep_vba)
  File "/usr/local/lib/python2.7/site-packages/openpyxl/reader/excel.py", line 204, in _load_workbook
    parsed_styles = read_style_table(archive)
  File "/usr/local/lib/python2.7/site-packages/openpyxl/reader/style.py", line 203, in read_style_table
  File "/usr/local/lib/python2.7/site-packages/openpyxl/reader/style.py", line 55, in parse
  File "/usr/local/lib/python2.7/site-packages/openpyxl/reader/style.py", line 81, in parse_dxfs
  File "/usr/local/lib/python2.7/site-packages/openpyxl/descriptors/serialisable.py", line 43, in from_tree
    obj = desc.expected_type.from_tree(el)
  File "/usr/local/lib/python2.7/site-packages/openpyxl/descriptors/serialisable.py", line 52, in from_tree
    return cls(**attrib)
TypeError: __init__() got an unexpected keyword argument 'mergeCell'

Version 2.1.2 is unaffected.

Comments (12)

  1. CharlieC

    According to the specification this attribute is not allowed, though the validator doesn't flag it even if it does pick up other things. Which version of which application was used to create the file? The attribute may have been allowed in an earlier version of the specification, though I can't find it.

    Unfortunately, it's not really possible at the moment to make openpyxl fault tolerant but I also don't think it's reasonable to try and add a workaround for this.

    <xsd:complexType name="CT_CellAlignment">
    <xsd:attribute name="horizontal" type="ST_HorizontalAlignment" use="optional"/>
    <xsd:attribute name="vertical" type="ST_VerticalAlignment" use="optional"/>
    <xsd:attribute name="textRotation" type="xsd:unsignedInt" use="optional"/>
    <xsd:attribute name="wrapText" type="xsd:boolean" use="optional"/>
    <xsd:attribute name="indent" type="xsd:unsignedInt" use="optional"/>
    <xsd:attribute name="relativeIndent" type="xsd:int" use="optional"/>
    <xsd:attribute name="justifyLastLine" type="xsd:boolean" use="optional"/>
    <xsd:attribute name="shrinkToFit" type="xsd:boolean" use="optional"/>
    <xsd:attribute name="readingOrder" type="xsd:unsignedInt" use="optional"/>
  2. Tim Smith reporter

    I received the file from an analysis vendor; I asked their customer service rep and they say "I believe [the analysts] use MS Excel 2007" but that's maybe not the whole story.

  3. CharlieC

    Personally, I'm not very keen on continuing to support Office 2007 as it doesn't really support the specification which was subsequently fast-tracked by Microsoft through the standardisation process. Added to this is the fact that I can't test. However, I also don't want to be too dogmatic about this.

    The easiest solution is to allow the keyword argument and just ignore it. It would be possible to add a warning about this but as I've no idea what the attribute means in this context and suspect it can quite happily be silently ignored I don't really see the need for a warning. Maybe you could add it locally to your code and see what other surprises pop-up?

    I have found a reference to the attribute: https://books.google.de/books?id=-ZtCAwAAQBAJ&pg=PT62&lpg=PT62&dq=excel+cellalignment+mergeCell+attribute&source=bl&ots=f0a19ZbR_x&sig=0hVDHZwjvrVk_snCbzx-Szxixmk&hl=de&sa=X&ved=0CGYQ6AEwCGoVChMIqPjIrLmExgIVRrgUCh23hwB2#v=onepage&q=excel%20cellalignment%20mergeCell%20attribute&f=false

    The best solution, of course, would be for the vendor to update their templates but I don't think we should expect that to happen.

  4. CharlieC

    For the record, this is a legacy attribute of Excel 2007 and not part of the specification: """ From [MS-OE376]: 2.1.720 Part 4 Section 3.8.1, alignment (Alignment) a. The standard does not contain a @mergeCell attribute on the alignment element. Excel allows @mergeCell to be written on the alignment element. @mergeCell is not used by Office and is not necessary for interoperability. This note applies to the following products: 2007, 2007 SP1, 2007 SP2. """

  5. Log in to comment