求xml方式导出excel数字变成文本的解决办法
项目中导出excel的代码如下this.Response.Clear();
this.Response.ContentType = "application/vnd.ms-excel";
this.Response.Charset = "GB2312";
this.Response.AddHeader("Content-Disposition", "attachment; filename=aaa.xls");
this.Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
System.Xml.Xsl.XslCompiledTransform xtExcel = new System.Xml.Xsl.XslCompiledTransform();
xtExcel.Load(Server.MapPath("Excel.xsl"));
xtExcel.Transform(xml, null, this.Response.OutputStream);
this.Response.End();
其中Excel.xsl内的代码
<xsl:stylesheet version="1.0"
xmlns="urn:schemas-microsoft-com:office:spreadsheet"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
xmlns:user="urn:my-scripts"
xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:x="urn:schemas-microsoft-com:office:excel"
xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet">
<xsl:template match="/">
<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"
xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:x="urn:schemas-microsoft-com:office:excel"
xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"
xmlns:html="http://www.w3.org/TR/REC-html40">
<xsl:apply-templates/>
</Workbook>
</xsl:template>
<xsl:template match="/*">
<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>
<xsl:template match="/*/*">
<Row>
<xsl:apply-templates/>
</Row>
</xsl:template>
<xsl:template match="/*/*/*">
<Cell>
<Data ss:Type="String">
<xsl:value-of select="." />
</Data>
</Cell>
</xsl:template>
</xsl:stylesheet>
通过以上发现导出的excel数字列全是文本格式的,现在想修改为数字列全是数字格式,本人对XML和XSL都不熟悉,该怎么修改? --------------------编程问答-------------------- 这个需要设置excel单元格的格式为数字型。与导出无关。 --------------------编程问答-------------------- 有个叫NPOI的Excel组件可以做这个事。
当然Office组件的com调用也可以,稍微麻烦一点
--------------------编程问答--------------------
怎么设置? --------------------编程问答-------------------- http://bbs.csdn.net/topics/310024279 --------------------编程问答--------------------
这个我也看了,没看明白最后怎么解决的:
<xsl:template match="/*/*/数值列名"> <Cell><Data ss:Type="String"> <xsl:value-of select="."/> </Data></Cell> </xsl:template>这个还是String类型的处理方法,没有说明数字型处理?再则多个“数值列名”怎么排列? --------------------编程问答-------------------- 求助呀!55555
补充:.NET技术 , C#