Below is the method I'm using to export my gridview data to Excel. The user has asked if I can name the worksheet tab. Any ideas? Thanks in advance!
Private Sub btnExportToExcel_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnExportToExcel.Click
Dim form As New HtmlForm
Dim strAttachment As String
Dim stw As StringWriter
Dim htextw As HtmlTextWriter
stw = New StringWriter
strAttachment = "attachment; filename=" & strAppName & ".xls"
HttpContext.Current.Response.ClearContent()
HttpContext.Current.Response.AddHeader("content-disposition", strAttachment)
HttpContext.Current.Response.ContentType = "application/vnd.ms-excel"
htextw = New HtmlTextWriter(stw)
form.Controls.Add(CType(Session("gridViewControl"), Control))
Me.Controls.Add(form)
form.RenderControl(htextw)
Response.Write("<b>" & txtTitle.Text & "</b><br />")
Response.Write(stw.ToString())
Response.Flush()
Response.Close()
HttpContext.Current.ApplicationInstance.CompleteRequest()
End Sub