What does the “s” attribute signify in a cell tag in XLSX

后端 未结 2 1594
天命终不由人
天命终不由人 2021-01-02 01:38

In the XML of a worksheet in an XLSX file (Excel 2007) cell tags that have a \"t\" attribute equal to \"s\" are string types. The value tag inside the c needs to be looked

相关标签:
2条回答
  • 2021-01-02 02:07

    The s attribute refers that is equal to 237, point to the 237th element found in parent element in the styles.xml file contained in the xlsx file.

    If the cell value is a date, the element can be similar to the following code

    <xf numFmtId="167" 
        fontId="6" 
        fillId="0" 
        borderId="6" 
        xfId="3" 
        applyNumberFormat="1" 
        applyFont="1" 
        applyFill="1" 
        applyBorder="1" 
        applyAlignment="1">
            <alignment horizontal="center"/>
    </xf>
    

    At this point we don't see that this cell represent a date type. To understand that, we must find the <numFmtId> with "167" as key.

    This value can be found at begin of styles.xml file

    <numFmts count="7">
        <numFmt numFmtId="164" formatCode="[$-409]d\-mmm\-yy;@"/>
        <numFmt numFmtId="165" formatCode="0.000"/>
        <numFmt numFmtId="166" formatCode="0.0"/>
        <numFmt numFmtId="167" formatCode="[$-409]d\-mmm\-yyyy;@"/>
        <numFmt numFmtId="168" formatCode="0.0%"/>
        <numFmt numFmtId="169" formatCode="00000"/>
        <numFmt numFmtId="170" formatCode="0.0000"/>
    </numFmts>
    

    The line with numFmtId="167" indicate that the cell's value is a date formatted using following string "[$-409]d-mmm-yyyy;@"

    In resume, to find if a cell contains a number or date we must

    1. find the S (=style) attribute of <c> element
    2. find the numFmtId attribute of the <xf> element in styles.xml file in xlsx file.
    3. find the formatCode attribute of <numFmt> that has numFmtId as key
    4. see if format is a date format or a number format

    I hope that can help others.

    0 讨论(0)
  • 2021-01-02 02:16

    The s attribute refers to a style. "237" is a style defined in the styles.xml file.

    <v>39448</v>

    ...is most likely a date in double format. And the style 237 tells excel to display 39448 in date format.

    You can see an example of how this works here: http://blogs.msdn.com/b/brian_jones/archive/2007/05/29/simple-spreadsheetml-file-part-3-formatting.aspx

    0 讨论(0)
提交回复
热议问题