项目中导出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都不熟悉,该怎么修改?
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都不熟悉,该怎么修改?
解决方案 »
- cmd.parameters.add()与不用这个有什么区别?
- 两种类的声明方式有何不同?
- 如何从DataSet更新到数据库
- 关于C# Winform RichTextBox Rtf格式文本追加的问题
- 能在vs.net2005上安裝ActiveX第三方組件嗎?如果可以,請問如何裝。
- 执行insert 语句,怎样插入时间呢?
- 一个特别基础的问题, 就当送分了, 谢谢大哥们
- 在Winform里用AxWebBrowser打开Word后,另打开一个新的Word文件。在AxWebBrowser里的word不能操作了。
- asp.net事件 无法创建应用程序域............. 寻找解决方案
- 怎么样得到TREEVIEW和LISTVIEW里节点的名称和ID呀?
- DataGridView数据显示的问题
- 一段非常诡异的代码,求助,在线等
当然Office组件的com调用也可以,稍微麻烦一点
这个还是String类型的处理方法,没有说明数字型处理?再则多个“数值列名”怎么排列?