DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world
Export Data Fro Grid View To Excel In Asp.net
// export data fro grid view to excel in asp.net
Private Sub ExportDataToExcel(ByVal myDataTable As DataTable)
Dim fileName As String = ""
Response.Clear()
Response.ContentType = "application/vnd.ms-excel"
fileName = "MyFile"
Response.AddHeader("Content-Disposition", "filename=" & fileName & DateTime.Now.Ticks & ".xls")
Response.Charset = ""
Dim sw As New StringWriter
Dim htw As New HtmlTextWriter(sw)
Dim myGrid As New GridView
myGrid.AllowPaging = False
myGrid.DataSource = myDataTable
myGrid.DataBind()
myGrid.RenderControl(htw)
Response.Write(sw.ToString())
Response.End()
myGrid.Dispose()
End Sub





