Confusing behaviour of Excel table style

Yevhen Rezohlazov 1 Reputation point
2021-04-26T23:58:05.737+00:00

Hi,

I don't understand Excel's behaviour when viewing a document with a table.
The table has a style: white background and orange text and borders.
Cell A2 takes background color from the table style, but cell A3 overrides the table style color
In sheet1.xml the style for A2 is 3, and for A3 it is 5.
Those two styles are absolutely identical, except fillId:

<cellXfs count="6">  
        <xf numFmtId="0" fontId="0" fillId="2" borderId="0" xfId="0"/>  
        <xf numFmtId="0" fontId="0" fillId="3" borderId="0" xfId="0" applyFill="1"/>  
        <xf numFmtId="0" fontId="0" fillId="3" borderId="0" xfId="0" applyFill="1" applyAlignment="1">  
            <alignment vertical="center"/>  
        </xf>  
        <xf numFmtId="0" fontId="0" fillId="2" borderId="0" xfId="0" applyFont="1" applyFill="1" applyBorder="1" applyAlignment="1">  
            <alignment vertical="center"/>  
        </xf>  
        <xf numFmtId="0" fontId="4" fillId="2" borderId="0" xfId="0" applyFont="1" applyFill="1" applyBorder="1"/>  
        <xf numFmtId="0" fontId="0" fillId="4" borderId="0" xfId="0" applyFont="1" applyFill="1" applyBorder="1" applyAlignment="1">  
            <alignment vertical="center"/>  
        </xf>  
    </cellXfs>  

They have fillIds 2 and 4 respectively. But the fill styles 2 and 4 are identical as well!

<fills count="5">  
    <fill>  
        <patternFill patternType="none"/>  
    </fill>  
    <fill>  
        <patternFill patternType="gray125"/>  
    </fill>  
    <fill>  
        <patternFill patternType="solid">  
            <fgColor theme="9"/>  
            <bgColor indexed="64"/>  
        </patternFill>  
    </fill>  
    <fill>  
        <patternFill patternType="solid">  
            <fgColor theme="0"/>  
            <bgColor indexed="64"/>  
        </patternFill>  
    </fill>  
    <fill>  
        <patternFill patternType="solid">  
            <fgColor theme="9"/>  
            <bgColor indexed="64"/>  
        </patternFill>  
    </fill>  
</fills>  

I can flip the background colors if I flip the fillIds of the cells, so it's not tied to cell position or style index.
Somehow Excel knows that it should not override the table style with fill #2, but it should override it with fill #4.
What am I missing here? How does it know which style to use?

Thank you,
Yevhen

91501-styles.xml
91502-table1.xml
91511-theme1.xml
91512-sheet1.xml

Office Open Specifications
Office Open Specifications
Office: A suite of Microsoft productivity software that supports common business tasks, including word processing, email, presentations, and data management and analysis.Open Specifications: Technical documents for protocols, computer languages, standards support, and data portability. The goal with Open Specifications is to help developers open new opportunities to interoperate with Windows, SQL, Office, and SharePoint.
127 questions
{count} votes

4 answers

Sort by: Most helpful
  1. Hung-Chun Yu 976 Reputation points Microsoft Employee
    2021-05-19T07:43:05.15+00:00

    Hi Yevhen

    What you described is expected behavior. You need to exam sheet1.xml instead when you changed the style for particular cell. Where you should able to find the following <sheetData> section

    <sheetData>
            <row r="1" spans="1:7" s="1" customFormat="1" ht="30" x14ac:dyDescent="0.4">
                <c r="A1" s="4" t="s">
                    <v>0</v>
                </c>
                <c r="E1" s="6" t="s">
                    <v>3</v>
                </c>
                <c r="G1" s="1" t="s">
                    <v>4</v>
                </c>
            </row>
            <row r="2" spans="1:7" ht="21" customHeight="1" x14ac:dyDescent="0.3">
                <c r="A2" s="3" t="s">
                    <v>1</v>
                </c>
                <c r="E2" s="7" t="s">
                    <v>1</v>
                </c>
                <c r="G2" s="2" t="s">
                    <v>5</v>
                </c>
            </row>
            <row r="3" spans="1:7" ht="21" customHeight="1" x14ac:dyDescent="0.3">
                <c r="A3" s="5" t="s">
                    <v>2</v>
                </c>
                <c r="E3" s="7" t="s">
                    <v>2</v>
                </c>
                <c r="G3" s="5" t="s">
                    <v>6</v>
                </c>
            </row>
        </sheetData>
    
    Lets use <c r="A1" s="4" t="s"> as an example 
    

    Where <c stands for Cell
    r stands references to cell “A1”
    s (Style index) of “4”
    t (Cell Data Type) of “s” which would be type string.

    If you change the style of cell “A1” to something else save it. You will see that Style Index now will be updated for "A1". You might have noticed that no change take place with styles.xml.

    For detail references on all the Cell Parts, please refer to ISO/IEC 29500-1:2016 Section 18.3.1.4 c (Cell)

    Hopefully, I answered your question.


  2. Hung-Chun Yu 976 Reputation points Microsoft Employee
    2021-05-24T20:10:00.087+00:00

    We believed we found the issue, under sheet1.xml

        <sheetData>
            <row r="1" spans="1:1" s="1" customFormat="1" ht="30" x14ac:dyDescent="0.4">
                <c r="A1" s="4" t="s">
                    <v>0</v>
                </c>
            </row>
            <row r="2" spans="1:1" ht="21" customHeight="1" x14ac:dyDescent="0.3">
                <c r="A2" s="3" t="s">
                    <v>1</v>
                </c>
            </row>
            <row r="3" spans="1:1" ht="21" customHeight="1" x14ac:dyDescent="0.3">
                <c r="A3" s="5" t="s">
                    <v>2</v>
                </c>
            </row>
        </sheetData>
    

    where <c r="A3" s="5" t="s"> its using 6th Style, they are 0 base. Yet, we only 5 of them defined in <cellStyleXfs count="5">

        <cellStyleXfs count="5">
            <xf numFmtId="0" fontId="0" fillId="2" borderId="0"/>
            <xf numFmtId="0" fontId="2" fillId="0" borderId="0" applyNumberFormat="0" applyFill="0" applyProtection="0">
                <alignment vertical="center"/>
            </xf>
            <xf numFmtId="0" fontId="1" fillId="0" borderId="0" applyNumberFormat="0" applyFill="0" applyProtection="0">
                <alignment vertical="center"/>
            </xf>
            <xf numFmtId="0" fontId="3" fillId="0" borderId="0" applyNumberFormat="0" applyFill="0" applyProtection="0">
                <alignment vertical="center"/>
            </xf>
            <xf numFmtId="0" fontId="4" fillId="2" borderId="0" applyNumberFormat="0" applyProtection="0"/>
        </cellStyleXfs>
    

    Since s="5" doesn't even exist so Excel probably just uses the default style which is "Normal" and has that brown bg.

    0 comments No comments

  3. Hung-Chun Yu 976 Reputation points Microsoft Employee
    2021-05-19T19:45:55.873+00:00

    <sheetData>
    <row r="1" spans="1:1" s="1" customFormat="1" ht="30" x14ac:dyDescent="0.4">
    <c r="A1" s="4" t="s">
    <v>0</v>
    </c>
    </row>
    <row r="2" spans="1:1" ht="21" customHeight="1" x14ac:dyDescent="0.3">
    <c r="A2" s="3" t="s">
    <v>1</v>
    </c>
    </row>
    <row r="3" spans="1:1" ht="21" customHeight="1" x14ac:dyDescent="0.3">
    <c r="A3" s="5" t="s">
    <v>2</v>
    </c>
    </row>
    </sheetData>

            <c r="A2" s="3" t="s">  Cell A2 is using style ID "3"
            <c r="A3" s="5" t="s">  Cell A3 is using style ID "5"
    

    StyleID "3" is defined as

            <font>
                <sz val="55"/>
                <color theme="4"/>
                <name val="Franklin Gothic Medium"/>
                <family val="2"/>
                <scheme val="major"/>
            </font>
    

    StyleID "5" is defined as

            <font>
                <sz val="24"/>
                <color theme="0"/>
                <name val="Franklin Gothic Medium"/>
                <family val="2"/>
                <scheme val="minor"/>
            </font>
    

    One way to see the difference is use different Font name for each style, doing so, will help you see the differences much easier.

    They are defined in styles.xml

        <fonts count="5" x14ac:knownFonts="1">
            <font>
                <sz val="11"/>
                <color theme="0"/>
                <name val="Franklin Gothic Medium"/>
                <family val="2"/>
                <scheme val="minor"/>
            </font>
            <font>
                <sz val="55"/>
                <color theme="6"/>
                <name val="Franklin Gothic Medium"/>
                <family val="2"/>
                <scheme val="minor"/>
            </font>
            <font>
                <sz val="55"/>
                <color theme="4"/>
                <name val="Franklin Gothic Medium"/>
                <family val="2"/>
                <scheme val="major"/>
            </font>
            <font>
                <sz val="55"/>
                <color theme="5"/>
                <name val="Franklin Gothic Medium"/>
                <family val="2"/>
                <scheme val="minor"/>
            </font>
            <font>
                <sz val="24"/>
                <color theme="0"/>
                <name val="Franklin Gothic Medium"/>
                <family val="2"/>
                <scheme val="minor"/>
            </font>
        </fonts>
    

    Hence you see the difference in visual effect. Does this helped?


  4. Hung-Chun Yu 976 Reputation points Microsoft Employee
    2021-05-24T23:47:15.733+00:00

    We believed we found the reason.

    18.8.15 dxfs (Formats)
    This element contains the master differential formatting records (dxf's) which define formatting for all non-cell
    formatting in this workbook. Whereas xf records fully specify a particular aspect of formatting (e.g., cell borders)
    by referencing those formatting definitions elsewhere in the Styles part, dxf records specify incremental (or
    differential) aspects of formatting directly inline within the dxf element. The dxf formatting is to be applied on
    top of or in addition to any formatting already present on the object using the dxf record.

    So the dxf records apply formatting on top of formatting done by cell (xfs) formatting

    Here is the repro steps

    1. Apply normal cell format to selected cells (should have brown background now).
    2. Convert those cells into a Table
    3. Apply Custom Table Style
    4. Exam the Style.xml for the new Table..

    Hoped this help.

    0 comments No comments