What does the "s" attribute signify in a cell tag in XLSX
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 up and converted via the sharedStrings document. But, some cells have s="237" and no t attribute at all. The value tag has an integer like 39448 which does not relate to the sharedStrings document. The value as it appears in Excel is a date 1/1/2008.
What does the s attribute signify in a c tag in XLSX?
Unknown value
<c r="B47" s="237">
开发者_运维知识库 <v>39448</v>
</c>
Shared String value
<c r="C47" t="s">
<v>7</v>
</c>
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
- find the S (=style) attribute of <c> element
- find the numFmtId attribute of the <xf> element in styles.xml file in xlsx file.
- find the formatCode attribute of <numFmt> that has numFmtId as key
- see if format is a date format or a number format
I hope that can help others.
精彩评论