解决如何在 Excel 中将值格式化为数字的方法是询问 Excel 本身!或者更确切地说,在 Excel 中打开一个空白工作表,在字段中输入一个值,格式为数字,然后将工作表保存为 Xml 电子表格 2003 格式。然后在记事本或类似工具中打开文件,看看实际做了什么。
在这种情况下,您可能会看到 Excel 添加了Style元素,可能像这样
<Style ss:ID="s62">
<NumberFormat ss:Format="Fixed"/>
</Style>
或者可能像这样(会有很多方法来格式化数字)
<Style ss:ID="s63">
<NumberFormat ss:Format="#,##0.00"/>
</Style>
然后,这只是在表格单元格上引用样式以及为数据设置正确类型的情况。像这样
<Row>
<Cell ss:StyleID="s62"><Data ss:Type="Number">123</Data></Cell>
</Row>
<Row>
<Cell ss:StyleID="s63"><Data ss:Type="Number">1233</Data></Cell>
</Row>
请记住,样式元素必须放置在您上面的工作表元素之前的父样式中。像这样的东西,也许...
<xsl:template match="/*">
<Styles>
<Style ss:ID="Default" ss:Name="Normal">
<Alignment ss:Vertical="Bottom"/>
<Borders/>
<Font ss:FontName="Calibri" x:Family="Swiss" ss:Size="11" ss:Color="#000000"/>
<Interior/>
<NumberFormat/>
<Protection/>
</Style>
<Style ss:ID="s62">
<NumberFormat ss:Format="Fixed"/>
</Style>
<Style ss:ID="s63">
<NumberFormat ss:Format="#,##0.00"/>
</Style>
</Styles>
<Worksheet>
<xsl:attribute name="ss:Name">
<xsl:value-of select="local-name(/*/*)" />
</xsl:attribute>
<Table x:FullColumns="1" x:FullRows="1">
<Row>
<xsl:for-each select="*[position() = 1]/*">
<Cell>
<Data ss:Type="String">
<xsl:value-of select="local-name()" />
</Data>
</Cell>
</xsl:for-each>
</Row>
<xsl:apply-templates/>
</Table>
</Worksheet>
</xsl:template>