Protected Sub Button1_Click(ByVal sender As Object, _     ByVal e As EventArgs)
        Response.AddHeader("content-disposition", "attachment;filename=FileName.xls")
        Response.Charset = String.Empty
        Response.ContentType = "application/vnd.xls"
        Dim sw As System.IO.StringWriter = _          New System.IO.StringWriter()
        Dim hw As System.Web.UI.HtmlTextWriter = _            New HtmlTextWriter(sw)
        GridView1.RenderControl(hw)
        Response.Write(sw.ToString())
        Response.End()
    End Sub

how do i set the format for that after click the button from gridview to excel file??

what's the code for this format??

in page tab:
orientation = landscape
scaling = 30%
paper size = A3
print quality = 300dpi

in margings tab:
width = 0.25
top = 0.25
height = 0.25
bottom = 0.25
left = 0.25
right = 0.25

center on page:
vertical = check

You can use third partly tool kit. to export in csv,xls or pdf format.

It CVS format is available on internet where from you can convert it.It is very easy to do.I am also used this work many time.I am looking for if you need any help.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.