13/03/2008, 08:43
|
| | Fecha de Ingreso: abril-2007
Mensajes: 63
Antigüedad: 17 años, 7 meses Puntos: 0 | |
Re: Exportar datagridview a excel Prueba con es codigo
Dim gv As GridView = Me.GridView2
gv.AllowPaging = False
gv.AllowSorting = False
gv.Columns(0).Visible = False
gv.DataBind()
Dim sw As New System.IO.StringWriter()
Dim hw As New System.Web.UI.HtmlTextWriter(sw)
Dim frm As HtmlForm = New HtmlForm()
Response.ContentType = "application/vnd.ms-excel"
Response.Cache.SetCacheability(HttpCacheability.No Cache)
Dim lcNomArc As String = ""
lcNomArc = "nombre archivo"
Response.AddHeader("content-disposition", "attachment;filename=" & lcNomArc & ".xls")
Response.Charset = ""
EnableViewState = False
Controls.Add(frm)
frm.Controls.Add(gv)
frm.RenderControl(hw)
Response.Write(sw.ToString())
Response.End() |