项目中导出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都不熟悉,该怎么修改?

解决方案 »

  1.   

    这个需要设置excel单元格的格式为数字型。与导出无关。
      

  2.   

    有个叫NPOI的Excel组件可以做这个事。
    当然Office组件的com调用也可以,稍微麻烦一点
      

  3.   

    http://bbs.csdn.net/topics/310024279
      

  4.   

    这个我也看了,没看明白最后怎么解决的:<xsl:template match="/*/*/数值列名">   <Cell><Data ss:Type="String">     <xsl:value-of select="."/>   </Data></Cell> </xsl:template> 
    这个还是String类型的处理方法,没有说明数字型处理?再则多个“数值列名”怎么排列?