Visual Basic - exportar datagrid en vb6

Life is soft - evento anual de software empresarial
 
Vista:

exportar datagrid en vb6

Publicado por miguel (5 intervenciones) el 11/04/2019 21:52:38
quiero exportar todo lo que arroje la consulta del datagrid y este codigo no hace nada, como podria mejorarlo


1
2
3
If sbgrid1.Rows > 0 Then
    sbgrid1.Export ssExportTypeText, ssExportFieldNames & ssExportAllRows, App.Path & "\Exportados\" & sbgrid1.Caption & ".txt"
End If
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

exportar datagrid en vb6

Publicado por alfonso hernandez (67 intervenciones) el 23/05/2019 20:00:17
hola

esto en un boton y asegurate de trabajar con ado conectado con el datagrid y la base si no adaptalo y trabajar con office 2010 no lo he probado con otras versiones

1
2
3
4
5
6
7
8
9
10
11
If MsgBox("DESEA CREAR UNA PLANILLA EXCEL CON EL CONTENIDO DE ESTE FORMULARIO", vbYesNo, "MENSAJE") = vbYes Then
If Adodc1.Recordset.EOF = True Then
Adodc1.Refresh
Screen.MousePointer = vbDefault
MsgBox "No hay datos para Exportar a Excel"
Else
Adodc1.Recordset.MoveFirst
Call exportar_Datagrid(DataGrid1, DataGrid1.ApproxCount)
Screen.MousePointer = vbDefault
End If
End If




pon esto en un modulo


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
'liberias de exportacion a excel
Dim Obj_Excel   As Object
Dim Obj_Libro   As Object
Dim Obj_Hoja    As Object
 
Public Sub exportar_Datagrid(Datagrid As Datagrid, n_Filas As Long)
Dim i   As Integer
Dim j   As Integer
 
MousePointer = vbHourglass
 
If n_Filas = 0 Then
MsgBox "No hay datos para exportar a excel ": Exit Sub
Else
Set Obj_Excel = CreateObject("Excel.Application")
Set Obj_Libro = Obj_Excel.Workbooks.Add
Set Obj_Hoja = Obj_Excel.ActiveSheet
 
iCol = 0
 
For i = 0 To Datagrid.Columns.Count - 1
If Datagrid.Columns(i).Visible Then
iCol = iCol + 1
Obj_Hoja.Cells(1, iCol) = Datagrid.Columns(i).Caption
For j = 0 To n_Filas - 1
Obj_Hoja.Cells(j + 2, iCol) = Datagrid.Columns(i).CellValue(Datagrid.GetBookmark(j))
Next
End If
Next
 
Obj_Excel.Visible = True
 
With Obj_Hoja
.Rows(1).Font.Bold = True
.Rows(1).Font.Color = vbBlue
.Columns("A:Z").AutoFit
End With
End If
 
Set Obj_Hoja = Nothing
Set Obj_Libro = Nothing
Set Obj_Excel = Nothing
 
MousePointer = vbDefault
 
Exit Sub
 
End Sub
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
sin imagen de perfil
Val: 53
Ha disminuido 1 puesto en Visual Basic (en relación al último mes)
Gráfica de Visual Basic

exportar datagrid en vb6

Publicado por Emilio (27 intervenciones) el 13/03/2020 18:35:42
muchas gracias para Alfonso por la aportación. La he probado, pero al llegar a la primera fila, en la instrucción

1
Obj_Hoja.Cells(j + 2, iCol) = Datagrid.Columns(i).CellValue(Datagrid.GetBookmark(j))

me dice "Número de fila incorrecto". ¿Alguien sabe qué puede ser?
Muchas gracias
Emilio
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
sin imagen de perfil

exportar datagrid en vb6

Publicado por samuel (2 intervenciones) el 02/02/2023 22:25:53
a mi me dice, no se ha definido tipo por el usuario, en la linea
' Public Sub exportar_Datagrid(Datagrid As Datagrid, n_Filas As Long
como puedo solucionar ese problema??
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar