Foros del Web » Programación para mayores de 30 ;) » Programación General » Visual Basic clásico »

Subir excel de Listview a SQL

Estas en el tema de Subir excel de Listview a SQL en el foro de Visual Basic clásico en Foros del Web. Soy nuevo en VB6, tengo un Excel que lo estoy leyendo en un ListView.- Como puedo subir el contenido del gridview a excel?.- Toda ayuda ...
  #1 (permalink)  
Antiguo 25/03/2011, 13:11
 
Fecha de Ingreso: julio-2010
Mensajes: 90
Antigüedad: 13 años, 9 meses
Puntos: 0
Subir excel de Listview a SQL

Soy nuevo en VB6, tengo un Excel que lo estoy leyendo en un ListView.-

Como puedo subir el contenido del gridview a excel?.-

Toda ayuda sera Agradecida, gracias.-
  #2 (permalink)  
Antiguo 26/03/2011, 16:14
Avatar de Gakex  
Fecha de Ingreso: enero-2009
Mensajes: 137
Antigüedad: 15 años, 3 meses
Puntos: 4
Respuesta: Subir excel de Listview a SQL

me perdi! {-_^}
  #3 (permalink)  
Antiguo 28/03/2011, 07:15
Avatar de lokoman  
Fecha de Ingreso: septiembre-2009
Mensajes: 502
Antigüedad: 14 años, 7 meses
Puntos: 47
Respuesta: Subir excel de Listview a SQL

Hola!!
Para exportar un listview a excel:
Código vb:
Ver original
  1. 'LLAMADA
  2. Exportar_Excel ListView1, "NombreHoja", "NombreArchivo"
  3.  
  4.  
  5. 'SUB RUTINA
  6. Sub Exportar_Excel(lsvData As ListView, strNombreHoja As String, strNombreArchivo As String)
  7.     On Error GoTo SaveErr
  8.    
  9.     Dim TMP
  10.     Dim I, J As Double
  11.     Dim xlApp As Excel.Application
  12.     Dim xlBook As Excel.Workbook
  13.     Dim xlSheet As Excel.Worksheet
  14.     Dim CellCnt As Double 'contar las celdas
  15.    
  16.     Set xlApp = New Excel.Application 'asignar las referencias a las variables
  17.    Set xlBook = xlApp.Workbooks.Add
  18.     Set xlSheet = xlBook.Worksheets.Add
  19.    
  20.    
  21.     xlApp.ActiveSheet.PageSetup.CenterHorizontally = True
  22.     xlApp.ActiveSheet.PageSetup.LeftMargin = Application.InchesToPoints(0.22)
  23.     xlApp.ActiveSheet.PageSetup.RightMargin = Application.InchesToPoints(0.18)
  24.     xlApp.ActiveSheet.PageSetup.TopMargin = Application.InchesToPoints(0.34)
  25.     xlApp.ActiveSheet.PageSetup.BottomMargin = Application.InchesToPoints(0.34)
  26.    
  27.     xlApp.ActiveSheet.PageSetup.Orientation = xlPortrait
  28.     xlApp.ActiveWindow.DisplayGridlines = False
  29.    
  30.     I = 1       '"i" MARCA EL INICIO DE LOS DATOS DE LA TABLA
  31.    CellCnt = 1 'CONTEO DE COLUMNAS
  32.    
  33.     TMP = lsvData.ColumnHeaders.Item(1)  ' OBTENER EL HEADER ITEM DEL LISTVEW
  34.    For CellCnt = 1 To lsvData.ColumnHeaders.Count
  35.         xlSheet.Cells(I, CellCnt) = lsvData.ColumnHeaders(CellCnt).Text
  36.         xlSheet.Cells(I, CellCnt).Interior.ColorIndex = 33
  37.         xlSheet.Cells(I, CellCnt).Font.Bold = True
  38.         xlSheet.Cells(I, CellCnt).BorderAround xlContinuous
  39.         xlSheet.Cells(I, CellCnt).HorizontalAlignment = xlCenter
  40.         DoEvents
  41.     Next
  42.    
  43.     I = 2       '"i" MARCA EL INICIO DE LOS DATOS DE LA TABLA
  44.    CellCnt = 1 'CONTEO DE COLUMNAS
  45.    
  46.     For J = 1 To lsvData.ListItems.Count
  47.         TMP = lsvData.ListItems.Item(I - 1) ' OBTENER EL ITEM DEL LISTVEW
  48.        xlSheet.Cells(I, 1) = lsvData.ListItems(I - 1)
  49.         For CellCnt = 1 To lsvData.ColumnHeaders.Count - 1
  50.             xlSheet.Cells(I, CellCnt + 1) = lsvData.ListItems(I - 1).SubItems(CellCnt)
  51.         Next
  52.         DoEvents
  53.         I = I + 1
  54.        
  55.     Next J
  56.    
  57.     xlApp.Range("A5:I" & (lsvData.ListItems.Count + 2)).Sort Key1:=xlSheet.Range("A6"), Order1:=xlAscending, Header:= _
  58.         xlGuess, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
  59.         DataOption1:=xlSortNormal
  60.        
  61. 'Ajustar todas las columnas
  62.    For J = 1 To lsvData.ColumnHeaders.Count
  63.         xlSheet.Columns(J).AutoFit
  64.     Next J
  65.  
  66. 'Salvar la hoja de excel
  67.    xlSheet.Name = strNombreHoja
  68.    
  69.  
  70.     xlSheet.SaveAs "C:\" & strNombreArchivo & " - " & Replace(DateValue(Date), "/", "-") & ".xls"
  71.     MsgBox "Consulta exportada a Excel!!", vbInformation
  72.    
  73.     xlBook.Close
  74.     xlApp.Quit
  75.     Set xlApp = Nothing
  76.     Set xlBook = Nothing
  77.     Set xlSheet = Nothing
  78. Exit Sub
  79. SaveErr:
  80.     If Err.Number <> 32755 Then
  81.         MsgBox "Ocurrió un error!!" & vbNewLine & "[ " & Err.Description & " ]", vbExclamation
  82.     End If
  83. End Sub
  #4 (permalink)  
Antiguo 28/03/2011, 08:29
 
Fecha de Ingreso: julio-2010
Mensajes: 90
Antigüedad: 13 años, 9 meses
Puntos: 0
Respuesta: Subir excel de Listview a SQL

Gracias Lokoman, no ocupe la totalidad del codigo, pero me fue de gran ayuda! :)
  #5 (permalink)  
Antiguo 28/03/2011, 09:57
Avatar de lokoman  
Fecha de Ingreso: septiembre-2009
Mensajes: 502
Antigüedad: 14 años, 7 meses
Puntos: 47
Respuesta: Subir excel de Listview a SQL


Etiquetas: vb
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 13:11.