Reading underlines

Issue #800 resolved
Walter Gurr
created an issue

Excel uses the <u\> tag for underline, however this tag appears to not recognized by openpyxl. For example this does not come in with an underline from the openpyxl parser:

   <sz val="11"/>
   <color rgb="FF0000FF"/>
   <name val="Calibri"/>

When openpyxl sets underline in it's output it uses <u val="single"/>. This is accepted by Excel, but when Excel saves it reverts to `<u/>'.

   <color rgb="000000FF"/>
   <u val="single"/>

I'm using Excel 2010 and openpyxl 2.4.5.

Comments (5)

  1. CharlieC

    Thanks for the report. The problem stems from prolific but inconsistent use of both defaults and single valued child elements in the specification. single is the default value for the u element.

    To implement the specification faithfully would propagate this inconsistency into the API. So for example to set and underline would be something like:

    from openpyxl.styles.font import Font, Underline, Bold
    ft = Font()
    ft.underline = Underline()
    ft.bold = Bold()
    # set underline to double
    ft.underline.val = "double"

    I tried to avoid this in the API by removing the additional layer so that you can set the properties directly. But it looks like special casing when reading the style is required so that an empty element is treated the same as <u val="single" />

  2. Walter Gurr reporter

    I'm pretty sure this is related - when the builtin Hyperlink style is applied it removes the underline from the style. I'll check this on the next release.

  3. Log in to comment