开发者

export gridview to excel without the gridview formatting VB

I am able to export a gridview to excel, my problem is that I cannot figure out how to remove the formatting from coming over from the girdview. Here is the code I am using to export the gridview:

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click

    Response.Clear()
    Response.Charset = ""
    'Response.ContentType = "application/vnd.ms-excel"
    Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"

    Dim stringWrite = New System.IO.StringWriter()
    Dim htmlWrite As New System.Web.UI.HtmlTextWriter(stringWrite)

    GridView1.GridLines = GridLines.None

    GridView1.HeaderStyle.Font.Bold = True
    GridView1.DataSourceID = SqlDataSource1.ID
    GridView1.DataB开发者_开发技巧ind()

    GridView1.RenderControl(htmlWrite)

    Response.Write(stringWrite.ToString)
    Response.End()

End Sub


What I suggest that you should iterate datasource , append the content of each row into StringBuilder object and write that string to the response buffer.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜