您的位置:首页 > 其它

Ext.NET的GridPanel导出Excel

2016-07-20 17:05 405 查看
配置:

<Buttons>
<ext:Button runat="server" Text="导出为Excel" Icon="PageExcel" AutoPostBack ="true" OnClick ="ToExcel">
<Listeners>
<Click Fn="SaveData"></Click>
</Listeners>
</ext:Button>
</Buttons>


js:

var SaveData = function () {  App.GridData.setValue(Ext.encode(App.OnlineRecordListPanel.getRowsValues({ selectedOnly: false })));
}


VB:

Public Sub ToExcel(sender As Object, e As EventArgs)
Dim Detail As String = Me.GridData.Value.ToString
Dim eSubmit As New StoreSubmitDataEventArgs(Detail, Nothing)
Dim xml As XmlNode = eSubmit.Xml

Me.Response.Clear()
Me.Response.ContentType = "application/vnd.ms-excel"
Me.Response.AddHeader("Content-Disposition", "attachment; filename=在线记录.xls")
Dim xtExcel As New XslCompiledTransform
xtExcel.Load(AppDomain.CurrentDomain.BaseDirectory & ("\Excel.xsl"))
xtExcel.Transform(xml, Nothing, Me.Response.OutputStream)
Me.Response.End()
End Sub


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 <
9086
span class="hljs-attribute">ss:Type="String">
<xsl:value-of select="." />
</Data></Cell>
</xsl:template>

</xsl:stylesheet>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: