当前位置:首页 > 网络编程 > WEB编程 > ASP.net >  将datagrid的数据源到出导excel

 将datagrid的数据源到出导excel

点击次数:23 次 发布日期:2008-11-26 10:59:02 作者:源代码网
源代码网推荐      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 writer
源代码网推荐   Dim stringWrite As New System.IO.StringWriter
源代码网推荐   "create an htmltextwriter which uses the stringwriter
源代码网推荐   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 htmltextwriter
源代码网推荐   dg.RenderControl(htmlWrite)
源代码网推荐   "all that"s left is to output the html
源代码网推荐   response.Write(stringWrite.ToString)
源代码网推荐   response.End()
源代码网推荐   End Sub
源代码网推荐    做人要厚道,请注明转自酷网动力(www.ASPCOOL.COM)。
源代码网推荐


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