mira quie ten pongo un ejemplo:
If Used('mi_cursor_final')
Use In 'mi_cursor_final'
Endif
Use venta_productos.Dbf Alias 'mi_cursor_final'
x_registros = Afields(campos,'mi_cursor_final')
*x_periodo = 'Fecha inicial : '+ p_fecha_inicial + Space(10) + 'Fecha final : ' + p_fecha_final
xlCenter = -4108
xlBottom = -4107
xlContext = -5002
xlDiagonalDown = 5
xlDiagonalUp = 6
xlEdgeLeft = 7
xlEdgeTop = 8
xlEdgeBottom = 9
xlEdgeRight = 10
xlInsideVertical = 11
xlInsideHorizontal = 12
xlNone = -4142
xlContinuous = 1
xlAutomatic = -4105
xlHairline = 1
Wait Windows 'Creado el objeto Excel....' Nowait
oexcel = Createobject('excel.application')
oexcel.Workbooks.Add
If Type('oexcel') = 'O'
x_fila = 1
x_columna = 1
Wait Windows 'Generando encabezados...' Nowait
oexcel.cells(x_fila,x_columna).Select
oexcel.Selection.Font.Size = 12
oexcel.Selection.Font.Bold = .T.
oexcel.Selection.Value = 'EMPRESA DE LOS TRES COCO'
x_fila = x_fila + 1
oexcel.cells(x_fila,x_columna).Select
oexcel.Selection.Font.Size = 10
oexcel.Selection.Font.Bold = .T.
oexcel.Selection.Value = 'REPORTE DE PRODUCTO POR SUCURSAL'
x_fila = x_fila + 2
oexcel.Rows(x_fila).Select
oexcel.Selection.Font.Bold = .T.
For i = 1 To x_registros
x_columna = i
If x_columna = 1
oexcel.cells(x_fila,x_columna).Select
oexcel.Selection.ColumnWidth = 30
oexcel.cells(x_fila,x_columna).Value = campos(i,1)
Endif
If Mod(i,2) = 0 &&Or i = x_registros
oexcel.Columns(i).Select
oexcel.Selection.NumberFormat = "#,##0"
oexcel.Selection.ColumnWidth = 5.5
oexcel.Columns(i+1).Select
oexcel.Selection.NumberFormat = "#,##0.00"
oexcel.Selection.ColumnWidth = 8
If Substr(campos(i,1),Len(campos(i,1))-1,1) = '_'
oexcel.cells(x_fila,x_columna).Value = Substr(campos(i,1),1,Len(campos(i,1))-2)
Else
oexcel.cells(x_fila,x_columna).Value = campos(i,1)
Endif
oexcel.Range(oexcel.cells(x_fila,x_columna),oexcel.cells(x_fila,x_columna+1)).Select
With oexcel.Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.WrapText = .F.
.Orientation = 0
.AddIndent = .F.
.IndentLevel = 0
.ShrinkToFit = .F.
.ReadingOrder = xlContext
.MergeCells = .F.
Endwith
oexcel.Selection.Merge
If i = x_registros-1
oexcel.cells(x_fila,x_columna).Value = 'TOTAL'
Endif
Endif
Next
x_fila = x_fila + 1
For i = 2 To x_registros
x_columna = i
If Mod(i,2) = 0
oexcel.cells(x_fila,x_columna).Value = 'CANT'
Else
oexcel.cells(x_fila,x_columna).Value = 'MONTO'
Endif
Next
oexcel.Range(oexcel.Columns(1),oexcel.Columns(x_registros)).Select
oexcel.Rows(x_fila).Select
oexcel.Selection.Font.Bold = .T.
With oexcel.Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.WrapText = .F.
.Orientation = 0
.AddIndent = .F.
.IndentLevel = 0
.ShrinkToFit = .F.
.ReadingOrder = xlContext
.MergeCells = .F.
Endwith
Select mi_cursor_final
Go Top
Scan
x_columna = 0
x_fila = x_fila + 1
Wait Windows 'Enviando a excel el producto ----> ' + Alltrim(producto) Nowait
For i = 1 To x_registros
x_columna = x_columna + 1
x_valor = 'mi_cursor_final.' + campos(i,1)
x_tipo = campos(i,2)
If x_tipo = 'N'
oexcel.cells(x_fila,x_columna).Value = &x_valor
Else
oexcel.cells(x_fila,x_columna).Value = [']+&x_valor
Endif
Next
Endscan
oexcel.Rows(x_fila).Select
oexcel.Selection.Font.Bold = .T.
oexcel.Range(oexcel.cells(6,1),oexcel.cells(x_fila,x_columna)).Select
oexcel.Selection.BorderS(xlDiagonalDown).LineStyle = xlNone
oexcel.Selection.BorderS(xlDiagonalUp).LineStyle = xlNone
With oexcel.Selection.BorderS(xlEdgeLeft)
.LineStyle = xlContinuous
.ColorIndex = xlAutomatic
.Weight = xlHairline
Endwith
With oexcel.Selection.BorderS(xlEdgeTop)
.LineStyle = xlContinuous
.ColorIndex = xlAutomatic
.Weight = xlHairline
Endwith
With oexcel.Selection.BorderS(xlEdgeBottom)
.LineStyle = xlContinuous
.ColorIndex = xlAutomatic
.Weight = xlHairline
Endwith
With oexcel.Selection.BorderS(xlEdgeRight)
.LineStyle = xlContinuous
.ColorIndex = xlAutomatic
.Weight = xlHairline
Endwith
With oexcel.Selection.BorderS(xlInsideVertical)
.LineStyle = xlContinuous
.ColorIndex = xlAutomatic
.Weight = xlHairline
Endwith
With oexcel.Selection.BorderS(xlInsideHorizontal)
.LineStyle = xlContinuous
.ColorIndex = xlAutomatic
.Weight = xlHairline
Endwith
oexcel.Selection.Font.Size = 8
oexcel.Visible = .T.
Release oexcel
Else
Messagebox('Excel no esta instalado en este equipo.....' ,0 +64 , 'Advertencia')
Endif