Exportar tabla a excel
Sorry que te moleste con otra cosa pero tengo que je je, pues mira quiero exportar un cursor dentro de un grid a excel y no he podido lograrlo
1 Respuesta
Vaa... esa va fácil! :)
LOCAN lnrow
**--lnrow es el numero de fila donde
**--empezaran a llenarse o cargarse
**--los datos de tu cursor.
**--
LError = ON('error')
ON ERROR xlapp = NULL
xlapp = GETOBJECT('Excel Application')
ON ERROR &LError
IF ISNULL(xlapp)
xlapp = CREATEOBJECT('Excel.Application')
ENDIF
**--
WITH xlapp
.Visible = 'True'
.DisplayAlerts = 'False'
.Workbooks.ADD()
ENDWITH
**--
xlsheet = xlapp.ActiveSheet
**--Area y formato de impresión
WITH xlsheet.PageSetup
**Margenes
.LeftMargin = XLApp.InchesToPoints(0.2)
.RightMargin = XLApp.InchesToPoints(0.393700787401575)
.TopMargin = XLApp.InchesToPoints(0.393700787401575)
.BottomMargin = XLApp.InchesToPoints(0.6)
.HeaderMargin = XLApp.InchesToPoints(0)
.FooterMargin = XLApp.InchesToPoints(0.2)
**Centrar área
.CenterHorizontally = .t.
.Orientation = 2 &&landscape
ENDWITH
**--Tamano de columnas
WITH xlsheet
.COLUMNS("A:A").ColumnWidth = 8.00
.COLUMNS("B:B").ColumnWidth = 8.57
.COLUMNS("C:C").ColumnWidth = 8.57
.COLUMNS("D:D").ColumnWidth = 8.57
.COLUMNS("E:E").ColumnWidth = 8.57
.COLUMNS("F:F").ColumnWidth = 3.86
.COLUMNS("G:G").ColumnWidth = 7.86
.COLUMNS("H:H").ColumnWidth = 10.30
.COLUMNS("I:I").ColumnWidth = 4.00
.COLUMNS("J:J").ColumnWidth = 9.00
.COLUMNS("QUE:QUE").ColumnWidth = 29.00
.COLUMNS("L:L").ColumnWidth = 6.00
.COLUMNS("M:M").ColumnWidth = 6.00
.COLUMNS("N:N").ColumnWidth = 7.00
ENDWITH
**--Alineacion vertical de columnas
xlsheet.COLUMNS("A:A").VerticalAlignment = 2
xlsheet.COLUMNS("B:B").VerticalAlignment = 2
xlsheet.COLUMNS("C:C").VerticalAlignment = 2
xlsheet.COLUMNS("D:D").VerticalAlignment = 2
xlsheet.COLUMNS("E:E").VerticalAlignment = 2
xlsheet.COLUMNS("F:F").VerticalAlignment = 2
xlsheet.COLUMNS("G:G").VerticalAlignment = 2
xlsheet.COLUMNS("H:H").VerticalAlignment = 2
xlsheet.COLUMNS("I:I").VerticalAlignment = 2
xlsheet.COLUMNS("J:J").VerticalAlignment = 2
xlsheet.COLUMNS("QUE:K").VerticalAlignment = 2
xlsheet.COLUMNS("L:L").VerticalAlignment = 2
xlsheet.COLUMNS("M:M").VerticalAlignment = 2
xlsheet.COLUMNS("N:N").VerticalAlignment = 2
**--Alineacion horizontal de columnas
xlsheet.COLUMNS("A:A").HorizontalAlignment = 3
xlsheet.COLUMNS("B:B").HorizontalAlignment = 1
xlsheet.COLUMNS("F:F").HorizontalAlignment = 3
xlsheet.COLUMNS("G:G").HorizontalAlignment = 1
xlsheet.COLUMNS("H:H").HorizontalAlignment = 1
xlsheet.COLUMNS("I:I").HorizontalAlignment = 3
xlsheet.COLUMNS("J:J").HorizontalAlignment = 3
xlsheet.COLUMNS("QUE:K").HorizontalAlignment = 1
xlsheet.COLUMNS("L:L").HorizontalAlignment = 3
xlsheet.COLUMNS("M:M").HorizontalAlignment = 3
xlsheet.COLUMNS("N:N").HorizontalAlignment = 3
**------------**
**--Encabezado
Fila = 1
**--Tipo de letra a documento
xlsheet.Range("A:N").Font.Name = "Calibri"
xlsheet.Range("A:N").Font.Size = '9'
**Encabezado
**Combinamos celdas
Xlsheet.Range("A1:N1").Merge&&Nombre de empresa
Xlsheet.Range("A2:N2").Merge&&Terra_ Inventario
Xlsheet.Range("A3:N3").Merge&&Nombre de documento
Xlsheet.Range("A4:N4").Merge&&| |
**--
Xlsheet.Range("B5:E5").Merge&&Descripcion
Xlsheet.Range("J5:K5").Merge&&Proveedor
**--Titulos, fuente encabezado
xlsheet.Cells(1,1).Value = 'GROSSROSEN'
xlsheet.Cells(2,1).Value = 'Terra_ Inventario'
xlsheet.Cells(3,1).Value = 'Inventario'
xlsheet.Cells(1,1).HorizontalAlignment = 3
xlsheet.Cells(2,1).HorizontalAlignment = 3
xlsheet.Cells(3,1).HorizontalAlignment = 3
xlsheet.Range("A1:A1").Font.Name = "Calibri"
xlsheet.Range("A2:A2").Font.Name = "Courier New"
xlsheet.Range("A3:A3").Font.Name = "Calibri"
xlsheet.Range("A1:A1").Font.Bold = 'True'
xlsheet.Range("A3:A3").Font.Bold = 'True'
xlsheet.Range("A1:A1").Font.Size = '14'
xlsheet.Range("A2:A2").Font.Size = '10'
xlsheet.Range("A3:A3").Font.Size = '12'
**--Bordes
xlsheet.Range("A5:N5").Borders.LineStyle = 1&&Entradas
**--Titulos
xlsheet.Cells(5,1).Value = 'Codigo'
xlsheet.Cells(5,2).Value = 'Descripcion'
xlsheet.Cells(5,6).Value = 'Linea'
xlsheet.Cells(5,7).Value = 'U/Medida'
xlsheet.Cells(5,8).Value = 'Marca'
xlsheet.Cells(5,9).Value = 'Alma.'
xlsheet.Cells(5,10).Value = 'Proveedor'
xlsheet.Cells(5,12).Value = 'Minimo'
xlsheet.Cells(5,13).Value = 'Maximo'
xlsheet.Cells(5,14).Value = 'Estado'
**--Fuente titulos
xlsheet.Range("A5:N5").Font.Name = "Calibri"
xlsheet.Range("A5:N5").Font.Size = '10'
xlsheet.Range("A5:N5").Font.Bold = 'True'
**--Alineacion titulos
** Centrado = 3
**Izquierda = 1
**Derecha = 2
xlsheet.Cells(5,1).HorizontalAlignment = 3
xlsheet.Cells(5,2).HorizontalAlignment = 1
xlsheet.Cells(5,6).HorizontalAlignment = 3
xlsheet.Cells(5,7).HorizontalAlignment = 1
xlsheet.Cells(5,8).HorizontalAlignment = 1
xlsheet.Cells(5,9).HorizontalAlignment = 3
xlsheet.Cells(5,10).HorizontalAlignment = 3
xlsheet.Cells(5,12).HorizontalAlignment = 3
xlsheet.Cells(5,13).HorizontalAlignment = 3
xlsheet.Cells(5,14).HorizontalAlignment = 3
**--Alineacion datos
xlsheet.Cells(6,1).HorizontalAlignment = 3
xlsheet.Cells(6,2).HorizontalAlignment = 1
xlsheet.Cells(6,6).HorizontalAlignment = 3
xlsheet.Cells(6,7).HorizontalAlignment = 1
xlsheet.Cells(6,8).HorizontalAlignment = 1
xlsheet.Cells(6,9).HorizontalAlignment = 3
xlsheet.Cells(6,10).HorizontalAlignment = 3
xlsheet.Cells(6,11).HorizontalAlignment = 1
xlsheet.Cells(6,12).HorizontalAlignment = 3
xlsheet.Cells(6,13).HorizontalAlignment = 3
xlsheet.Cells(6,13).HorizontalAlignment = 3
**--Datos
SELECT micursor
*BROWSE
GO TOP
SCAN
xlsheet.Cells(lnRow,1).Value = codigo_producto
xlsheet.Cells(lnRow,2).Value = descripcion
*xlsheet.Cells(nfila,2).NumberFormat = "0;-0;;@"
xlsheet.Cells(lnRow,6).Value = numeroclase
*xlsheet.Cells(nfila,3).NumberFormat = "0;-0;;@"
xlsheet.Cells(lnRow,7).Value = unidad_medida
*xlsheet.Cells(nfila,4).NumberFormat = "0;-0;;@"
xlsheet.Cells(lnRow,8).Value = marca
*xlsheet.Cells(nfila,5).NumberFormat = "#,##0.00"
xlsheet.Cells(lnRow,9).Value = numeroalmacen
*xlsheet.Cells(nfila,6).NumberFormat = "#,##0.00"
xlsheet.Cells(lnRow,10).Value = codigoproveedor
*xlsheet.Cells(nfila,7).NumberFormat = "#,##0.00"
"
lnRow = lnRow+ 1
ENDSCAN
Este código te permite configurar las propiedades de la hoja de excel! Al final,,, seleccionas el cursor y asignas en cada celda el dato del campo que se descargara.
Avisame cualquier cosa! :)
- Compartir respuesta