当前位置:首页 > 网络编程 > 软件语言 > .NET > 将datagrid的数据源到出导excel

将datagrid的数据源到出导excel

点击次数:54 次 发布日期:2008-11-06 08:10:52 作者:源代码网
源代码网推荐
广告载入中
Public Shared Sub Convert(ByVal ds As System.Data.DataSet, ByVal response As System.Web.HttpResponse)
"first let"s clean up the response.object
response.Clear()
response.Charset = ""
"set the response mime type for excel
response.ContentType = "application/vnd.ms-excel"
"create a string 网络
Dim stringWrite As New System.IO.StringWriter
"create an htmltext网络 which uses the string网络
Dim htmlWrite As New System.Web.UI.HtmlTextWriter(stringWrite)
"instantiate a datagrid
Dim dg As New System.Web.UI.WebControls.DataGrid
"set the datagrid datasource to the dataset passed in
dg.DataSource = ds.Tables(0)
"bind the datagrid
dg.DataBind()
"tell the datagrid to render itself to our htmltext网络
dg.RenderControl(htmlWrite)
"all that"s left is to output the html
response.Write(stringWrite.ToString)
response.End()
End Sub 
 

源代码网推荐

源代码网供稿.
网友评论 (0)
会员中心
网络编程
本站推荐
网络编程之精华