locked
How to Filter Web Content When Export Gridview Data to Excel File RRS feed

  • Question

  • 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


      

    • Moved by Carl Cai Monday, July 21, 2014 1:37 AM (from vb) asp.net forum is more dedicated for these issues
    Friday, July 18, 2014 6:19 AM

Answers

  • Your code covers completely the Web user interface Asp.Net

    For that is a special forum from the division of Microsoft responsible for the marketing of it.

    http://forums.asp.net


    Success
    Cor

    Friday, July 18, 2014 7:29 AM