Foros del Web » Programación para mayores de 30 ;) » .NET »

Exportar a Excel o a Word

Estas en el tema de Exportar a Excel o a Word en el foro de .NET en Foros del Web. Buenos dias: Tengo una base de datos que quiero hacer es mediante vb.net, al hacer una consulta select exporte los datos bien a excel o ...
  #1 (permalink)  
Antiguo 02/02/2010, 02:50
 
Fecha de Ingreso: enero-2006
Mensajes: 263
Antigüedad: 18 años, 3 meses
Puntos: 1
Exportar a Excel o a Word

Buenos dias:

Tengo una base de datos que quiero hacer es mediante vb.net, al hacer una consulta select exporte los datos bien a excel o a word.

Tengo una plantilla ya hecha tipo:


COL1 COL2 COL3
Reg1 Reg1 Reg1
Reg2 Reg2 Reg2
. . .
Regx RegX RegX

Muchas gracias
  #2 (permalink)  
Antiguo 16/02/2010, 03:27
 
Fecha de Ingreso: julio-2009
Mensajes: 60
Antigüedad: 14 años, 9 meses
Puntos: 0
Respuesta: Exportar a Excel o a Word

Yo lo unico que te puedo decir es que contruyo un excel a partir de un dataset.
Aqui te dejo el boton que me ocntruye el excel.Un saludo

Protected Sub ImageButton_Excel_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs)

Try

Dim i, j As Integer
Dim ls_color1, ls_color2, ls_color As String
Dim li_color As Integer = 1
Dim dataset_grid As New DataSet
Dim directorio_base As String
Dim li_contador_productos As Integer
Dim cliente As String
Dim periodo As Integer

cliente = Me.txt_cliente_antiguo_id.Text
periodo = convertir_periodo_anno(Me.cmb_periodos.SelectedIte m.Text)
periodo = Integer.Parse(periodo)
Session("codigo_distribuidor") = cliente
Session("periodo") = periodo


dataset_grid = clase_gestionDimSQL.Devuelve_clientes_porcentaje(S ession("Usuario_red"), "Mantenimiento_actual2.aspx", Session("periodo"), Session("codigo_distribuidor"))

directorio_base = System.AppDomain.CurrentDomain.BaseDirectory()

Dim ofile As File
Dim oDir As DirectoryInfo

oDir = New DirectoryInfo(directorio_base & ConfigurationManager.AppSettings("\TEMPORAL\"))

If File.Exists(directorio_base & ConfigurationManager.AppSettings("\TEMPORAL\listad o_prioridades_distribuidores.xls")) Then
File.Delete(directorio_base & ConfigurationManager.AppSettings("\TEMPORAL\listad o_prioridades_distribuidores.xls"))
End If

li_contador_productos = dataset_grid.Tables(0).Rows.Count

If li_contador_productos > 0 Then

ls_color1 = "LightSteelBlue"
ls_color2 = "Lavender"
Response.Clear()

Response.AddHeader("Content-Disposition", "attachment; filename=" & directorio_base & "\TEMPORAL\listado_prioridades_distribuidores.xls" )

Response.ContentType = "application/vnd.ms-excel"

Response.Write("<table border='0' id='ctl00_ContentPlaceHolder1_GridView_productos'> ")
Response.Write("<tr>")
Response.Write("<td style='background-color: #6666ff; font-weight: bold; font-size: 14px;text-align: center; vertical-align: middle; width: 220px; border-top-style: solid; border-right-style: solid; border-left-style: solid; border-bottom-style: solid;'>Distribuidor</td><td style='background-color: #6666ff; font-weight: bold; font-size: 14px;text-align: center; vertical-align: middle; width: 100px; border-top-style: solid; border-right-style: solid; border-left-style: solid; border-bottom-style: solid;'>Periodo</td><td style='background-color: #6666ff; font-weight: bold; font-size: 14px;text-align: center; vertical-align: middle; width: 100px; border-top-style: solid; border-right-style: solid; border-left-style: solid; border-bottom-style: solid;'>Prioridad</td>")
Response.Write("</tr>")

For i = 0 To dataset_grid.Tables(0).Rows.Count - 1
If li_color = 1 Then
ls_color = ls_color1
li_color = 2
Else
ls_color = ls_color2
li_color = 1
End If
Response.Write(" <tr>")
For j = 0 To dataset_grid.Tables(0).Columns.Count - 1
If j = 0 Or j = 2 Or j = 3 Then
Response.Write(" <td style='background-color:" & ls_color & ";text-align: center;vertical-align: middle;border-right-style: solid; border-left-style: solid; border-bottom-style: solid;'>" & Server.HtmlEncode(dataset_grid.Tables(0).Rows(i).I tem(j).ToString) & "</td>")
Else
Response.Write(" <td style='background-color:" & ls_color & "; text-align: center;vertical-align: middle;border-right-style: solid; border-left-style: solid; border-bottom-style: solid;'>" & Server.HtmlEncode(dataset_grid.Tables(0).Rows(i).I tem(j).ToString) & "</td>")
End If

Next
Next
Response.Write("</table>")

Response.End()
End If






Catch ex As Exception

End Try
End Sub
  #3 (permalink)  
Antiguo 18/02/2010, 16:42
 
Fecha de Ingreso: febrero-2010
Ubicación: culiacan,sinaloa
Mensajes: 3
Antigüedad: 14 años, 2 meses
Puntos: 0
Respuesta: Exportar a Excel o a Word

Yo tengo este codigo, pero es para c#, no se si te pueda servir,solo que tienes que cargar unas librerias.

private void exportar()
{
string sArchivo;
try
{
sArchivo = Util.Utilerias.MostrarDialogoGuardar("Microsoft Excel Document",
"Microsoft Excel|*.xls",
"Activos");
}
catch (Exception ex)
{
Util.ManejoErrores.mostrarMensajeExcepcion(ex);
return;
}

if (!(sArchivo.Trim().Equals(string.Empty)))
{
Cursor cursorActual = Cursor.Current;
Cursor.Current = Cursors.WaitCursor;

try
{
DevExpress.XtraGrid.Export.BaseExportLink oLink = this.gridView1.CreateExportLink(new DevExpress.XtraExport.ExportXlsProvider(sArchivo)) ;
oLink.ExportTo(true);

Util.Utilerias.AbrirArchivoExportado(sArchivo);
}
catch (Exception ex)
{
Util.ManejoErrores.mostrarMensajeExcepcion(ex);
}
finally
{
Cursor.Current = cursorActual;
}
}
}

saludos espero te pueda ayudar, solo tienes que hacerlo en vb, pero igual te ayuda.
  #4 (permalink)  
Antiguo 08/07/2010, 09:34
Avatar de xrojas  
Fecha de Ingreso: noviembre-2009
Mensajes: 14
Antigüedad: 14 años, 4 meses
Puntos: 0
Respuesta: Exportar a Excel o a Word

yo tengo creada una hoja en Excel solo para ser llenada quiero que los campos del grid llenen esa hoja como podria hacerlo? o tengo que crear la hoja de excel desde codigo???

Etiquetas: excel, word
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 07:27.