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

拟墨画扇 提交于 2019-11-30 18:16:30

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

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.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!