Conditional formatting lost

Issue #493 resolved
vgrass
created an issue

Hi,

i've an issue with openpyxl 2.2.5. Conditinal formatting is lost just after loading a workbook and saving it without even changing any data. I've attached sample files. The file is even 3kb smaller afterwards.

from openpyxl import load_workbook


sFileName = 'test.xlsx'

ws = load_workbook(filename = sFileName)
ws.save(filename = sFileName)

Comments (9)

  1. CharlieC

    The problem is that the original file uses extensions to conditional formatting that are not covered in the specification. In this case all the conditional formatting is embedded as an extension.

    Which version of Office are you using? You might want to check the compatibility settings.

  2. CharlieC

    Images have always been lost when processing files. That will hopefully change in a future version.

    I think the formatting can be retained if the rule is expressed differently.

  3. CharlieC

    Yes, it's specified as an extension. If only it were as easy as supporting an additional tag. However, Excel does this by creating the extension and the format in one place at linking to it from another. This is tricky to manage, though we'll hopefully get round to it one day. If you look at the code it uses, almost anything would be preferable to it.

    Compare: classic formatting:

      <cfRule type="expression" priority="1" dxfId="1">
       <formula>
        $AA$6
       </formula>
    

    Excel 2010+

        <x14:cfRule type="containsText" priority="2" operator="containsText" id="{77F12508-0BE0-4B3F-9C57-4DEEF91E7B07}">
          <xm:f>
           NOT(ISERROR(SEARCH($AA$6,A1)))
          </xm:f>
          <xm:f>
           $AA$6
          </xm:f>
          <x14:dxf>
           <font>
            <color rgb="FF0000FF"/>
           </font>
           <fill>
            <patternFill>
             <bgColor rgb="FF99CCFF"/>
            </patternFill>
           </fill>
          </x14:dxf>
    
  4. Log in to comment