I need to export Gridview data to excel file and achieved the export function using attached code,everything is ok but the content of the excel file to which gridview data exported Contained all Web components,
sush as button,textbox,etc. I want to know how to filter those web components. The Code is following,Please help me,thanks.
If DataEmpty = False Then
Dim dt As DateTime = Now()
Dim Filename As String = dt.ToString("yyMMddhhmmss")
Filename = "UserReport_" + Filename + ".xls"
GridView_UserList.AllowPaging = False
GridView_UserList.Columns(0).Visible = False
GridView_UserList.DataSource = BindData()
GridView_UserList.DataBind()
GridView_UserList.HeaderRow.BackColor = Drawing.Color.White
GridView_UserList.HeaderRow.ForeColor = Drawing.Color.Black
HttpContext.Current.Response.Charset = "GB2312"
HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.UTF8
HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(Filename, System.Text.Encoding.UTF8).ToString())
HttpContext.Current.Response.ContentType = "application/vnd.ms-excel" GridView_UserList.Page.EnableViewState = False
Dim oStringWriter As StringWriter = New StringWriter
Dim oHtmlTextWriter As HtmlTextWriter = New HtmlTextWriter(oStringWriter)
Try
GridView_UserList.RenderControl(oHtmlTextWriter)
Response.Output.Write(oStringWriter.ToString)
Response.Flush()
Response.End()
Catch ex As Exception
WriteOperatorMsg("Export Excel file", Filename, "Failed", ex.Message.ToString)
End Try
End If