将datagrid的数据源到出导excel

时间:2010-02-25 17:23:46  来源:第二电脑网  作者:第二电脑网

  第二电脑网导读: = ""    '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 html...
  正文: 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
将datagrid的数据源到出导excel》由第二电脑网原创提供,转载请注明:http://www.002pc.com/master/College/Programming/aspnet/12902.html


关键字:

关于《将datagrid的数据源到出导excel》文章的评论

站内搜索: 高级搜索

热门搜索: Windows style 系统 tr IP QQ CPU 安装 function 注册 if td