Value error when loading file with invalid but common underline style element
I have an .xlsx
file that contains <u val="1"/>
in the embedded stylesheet xl/styles.xml
. This invalid value was written by the RubyXL library, due to a bug: https://github.com/weshatheleopard/rubyXL/issues/405
Here is the file: after_rubyxl_parse_write.xlsx
openpyxl
raises ValueError
when loading this file:
openpyxl.load_workbook("after_rubyxl_parse_write.xlsx")
Traceback (most recent call last):
... (stack trace omitted) ...
ValueError: Value must be one of {'singleAccounting', 'single', 'double', 'doubleAccounting'}
Excel loads the file happily and displays a single underline style in the cell. It also does the same for <u val="total nonsense value I hacked into here"/>
.
While this specific issue is caused by a bug in RubyXL, it looks like invalid values here may be more widespread: a post on StackOverflow suggests that Excel 2016 may also write some invalid underline styles.
Could openpyxl
be changed to interpret any invalid value of u/@val
as single
, to match Excel's behaviour?
Another couple of thoughts:
-
OpenXML documentation suggests that
none
is also a valid value, but it's not listed in theValueError
.none
should be allowed, and interpreted as no underscore (same as absence of<u>
element). - It would be nice if the
ValueError
message also stated the element name, the invalid attribute value and the embedded XML file. That would have made it easier for me to debug the problem.