Handle invalid styles gracefully

Issue #935 wontfix
Brett Haydon
created an issue

When opening an existing .xlsx (that was converted from an xls) I get an error when the styles are being bound to the workbook.

openpyxl/reader/excel.py", line 221, in load_workbook
    apply_stylesheet(archive, wb) # bind styles to workbook

Specifically in this instance it appears to be something to do with the font.

openpyxl/descriptors/base.py", line 89, in __set__
    raise ValueError('Max value is {0}'.format(self.max))
ValueError: Max value is 14

Since I don't want to retain the style - I just want to access the data without having to manually remove the style it would be nice to ignore the existing styles rather than apply_stylesheet, but otherwise it would be nice to ignore value errors that are coming from the file itself.

Comments (7)

  1. CharlieC

    Ignoring styles isn't possible because they're required for deciding whether a number is a datetime object.

    It sounds like the file you have does not conform to the OOXML specification – I'm guessing it was not converted by MS Excel – it's not openpyxl's job to add workarounds for broken files.

  2. Brett Haydon reporter

    I opened the .xls and saved as .xlsx in Excel 2016 for the Mac. The file evidently was created by Crystal Decisions, so no doubt that’s where the problem has originated, but Excel itself has no trouble with the file. I worked around the issue by using xlrd to deal with legacy xls files.

  3. CharlieC

    Sounds like a good idea to work directly with the xls file. Excel is presumably using an internal BIFF engine for the conversion. FWIW the error stems from an invalid value for the font family which is defined as

    <xsd:simpleType name="ST_FontFamily">
        <xsd:restriction base="xsd:integer">
           <xsd:minInclusive value="0"/>
           <xsd:maxInclusive value="14"/>

    So the file is definitely invalid.

  4. Log in to comment