
08/05/2009, 13:16
|
 | | | Fecha de Ingreso: julio-2007 Ubicación: Montevideo (Uruguay)
Mensajes: 919
Antigüedad: 17 años, 7 meses Puntos: 13 | |
Respuesta: Enviar un dataset a excel Bueno te paso un ejemplo que tengo, modificalo a tu gusto y fijate que en lugar de hacerlo desde un dataset lo hago desde un gridview ya que de este le podes dar formato lindo a tu excel ok..
Private Sub ExportToExcel()
Dim sb As New StringBuilder()
Dim sw As New StringWriter(sb)
Dim htw As New HtmlTextWriter(sw)
Dim dg As New GridView
dg.AllowPaging = False
dg.PagerSettings.Visible = False
dg.AutoGenerateColumns = True
dg.RowStyle.HorizontalAlign = HorizontalAlign.Left
Dim Page As New Page()
Dim form As New HtmlForm()
dg.DataSource = LlenarParaExcel() 'esta es una funcion que ya lo debes tener hecha, te tiene que retornar un datatabla para llenar tu grilla
dg.DataBind()
Page.EnableEventValidation = False
Page.DesignerInitialize()
Page.Controls.Add(form)
form.Controls.Add(dg)
Page.RenderControl(htw)
Response.Clear()
Response.Buffer = True
Response.ContentType = "application/vnd.ms-excel"
Response.AddHeader("Content-Disposition", "attachment;filename=Datos.xls")
Response.Charset = "UTF-8"
Response.ContentEncoding = Encoding.Default
Response.Write(sb.ToString())
Response.End()
End Sub
Suerte.
__________________ Marcelo Davila. :. En Ignorante te conviertes al no preguntar, el que pregunta se nutre... :. |