我试图通过XSL在Excel中设置单元格的Type属性。它应该查看report / sheet / definition / column,并查看是否有type
属性。如果是,则应将“单元格类型”设置为该类型,并以全时(或日期时间)方式对其进行格式化。
我的xml数据:
<report>
<sheet>
<definition>
<columns>
<column name="Code" footerText="ISO Code" width="80" />
<column name="Time" footerText="Time" format="DateTime" width="58" type="DateTime" />
<column name="Country" footerText="Country" width="100" />
<column name="SomeNumber" footerText="Country" width="100" type="Number"/>
</columns>
</definition>
<data>
<table>
<row>
<column value="2020-04-02" key="DATE" />
</row>
<row>
<column value="123" />
<column value="10:30" />
<column value="Belarus" />
<column value="0" />
</row>
<row>
<column value="321" />
<column value="12:00" />
<column value="Austria" />
<column value="0" />
</row>
<row>
<column value="2020-04-03" key="DATE" />
</row>
<row>
<column value="456" />
<column value="08:00" />
<column value="USA" />
<column value="24" />
</row>
</table>
</data>
</sheet>
</report>
我尝试在单元格中打印出$ type和$ index,它们确实可以正确打印出来,但是当我尝试取$type
的值并用于<xsl:attribute name="ss:Type">
时,Excel为我提供了一个错误,说它在加载期间有问题。检出日志后,事实证明它无法将12:00
之类的值解析为Time(或者我应该说DateTime?)。我有两个问题:
2020-01-01
解析为DateTime是正常行为吗?<xsl:for-each select="data/table/row">
<ss:Row>
<xsl:variable name="set" select="column" />
<xsl:variable name="count" select="count($set)"/>
<xsl:for-each select="column">
<ss:Cell>
<xsl:variable name="index" select="position()"/>
<xsl:variable name="type" select="../../../definition/columns/column[$index]/@type"/>
<xsl:attribute name="ss:MergeAcross">
<xsl:choose>
<xsl:when test="$count>1">
<xsl:value-of select="0"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$mergeAcrossHeader"/>
</xsl:otherwise>
</xsl:choose>
</xsl:attribute>
<ss:Data>
<xsl:attribute name="ss:Type">
<xsl:choose>
<xsl:when test="$type!=''">
<xsl:value-of select="$type" />
</xsl:when>
<xsl:otherwise>
<xsl:text>String</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:attribute>
<xsl:value-of select="@value" />
</ss:Data>
</ss:Cell>
</xsl:for-each>
</ss:Row>
</xsl:for-each>