Ver Mensaje Individual
  #3 (permalink)  
Antiguo 27/09/2004, 20:27
Avatar de Mickel
Mickel
 
Fecha de Ingreso: mayo-2002
Ubicación: Lima, Peru
Mensajes: 4.619
Antigüedad: 22 años
Puntos: 7
Aca tengo un ejemplo que exporta los datos de una DataGrid al Excel. Digamos que la datagrid se llama dgr_Reporte

Código:
        Dim adt_Var As DataTable
        Dim tw As New System.IO.StringWriter
        Dim hw As New System.Web.UI.HtmlTextWriter(tw)
        Response.ContentType = "application/vnd.ms-excel"
        Response.ContentEncoding = System.Text.ASCIIEncoding.UTF7
        Response.Charset = "iso-8859-1"
        Me.EnableViewState = False
        adt_Var = (query a la base de datos)
        If Not (adt_Var Is Nothing OrElse adt_Var.Rows.Count = 0) Then
            dgr_Reporte.DataSource = adt_Var
            dgr_Reporte.CurrentPageIndex = 0
            dgr_Reporte.DataBind()
            dgr_Reporte.RenderControl(hw)
            Response.Write(tw.ToString())
            Response.End()
        End If