Buenas Noches amigos:
Le he dado varias vueltas a mi problema que me he visto en la necesidad de recurrir por su ayuda:
Necesito exportar un cursor a excel con subtotales y tengo dos problemas:
Explico:
Esta es la estructura de mi cursor:
Field Field Name Type Width Dec Index Collate Nulls Next Step
1 CODIGO Character 6 No
2 RAZONSOC Character 50 No
3 CUENTA Character 6 No
4 NOMCTA Character 50 No
5 FECHA Date 8 No
6 TD Character 2 No
7 NUMERO Character 10 No
8 REF Character 10 No
9 DEBE Numeric 15 2 No
10 HABER Numeric 15 2 No
11 SALDO Numeric 15 2 No
12 DIAS Numeric 10 No
13 D1A30 Numeric 15 2 No
14 D31A60 Numeric 15 2 No
15 D61A90 Numeric 16 2 No
16 D91A120 Numeric 15 2 No
17 D121A180 Numeric 15 2 No
18 D181A360 Numeric 15 2 No
19 DOVER360 Numeric 15 2 No
En la primera parte del evento click del boton exportar de mi formulario tengo la siguiente rutina:
SELECT * FROM report1 INTO CURSOR tmp3
SELECT tmp3
cTmp = Getenv("TEMP")+"" + Sys(2015) + ".Tmp"
Copy To (cTmp) Delimited With Tab
_Cliptext = Filetostr(cTmp)
oExcel= Createobject("Excel.Application")
oexcel.VISIBLE=.F.
With oExcel
.DisplayAlerts = .F.
.Workbooks.Add()
.Range("A2").PasteSpecial
.Range("A1:S1").Font.Bold = .T.
.Range("A1:S1").Interior.Color = RGB(230, 230, 230)
.Cells(1,1)="Código" &&A
.Cells(1,2)="Nombre/Razón Social" &&B
.Cells(1,3)="Cuenta" &&C
.Cells(1,4)="Descrpción de la Cuenta" &&D
.Cells(1,5)="Fecha" &&E
.Cells(1,6)="TD" &&F
.Cells(1,7)="Número" &&G
.Cells(1,8)="Ref" &&H
.Cells(1,9)="Debe" &&I
.Cells(1,10)="Haber" &&J
.Cells(1,11)="Saldo" &&K
.Cells(1,12)="Dias" &&L
.Cells(1,13)="D1A30" &&M
.Cells(1,14)="D31A60" &&N
.Cells(1,15)="D61A90" &&O
.Cells(1,16)="D91A120" &&P
.Cells(1,17)="D121A180" &&Q
.Cells(1,18)="D181A360" &&R
.Cells(1,19)="DOVER360" &&S
.Columns("A:Z").EntireColumn.AutoFit
.Columns("I:K").NumberFormat = "#,##0.00;[Red](#,##0.00)"
.Columns("M:S").NumberFormat = "#,##0.00;[Red](#,##0.00)"
.Range("A1").Select
ENDWITH
oExcel.Workbooks(1).SaveAs("c:\litocxc\xls\LitocxcD.xlsx")
lcXLSFile="c:\litocxc\xls\LitocxcD.xlsx"
oExcel.quit()
RELEASE oExcel
*** Pregunta 1:
A pesar que uso oExcel.quit() y release oExcel , para cerrar la aplicacion excel, éste se queda pegado en memoria
? cual es la forma correcta de cerrar el excel y quitarlo de memoria??
En la segunda parte, en este archivo excel (LitocxcD.xlsx) intento totalizarlo por el campo "CODIGO" ,
realiza el proceso pero lo totaliza por el campo "NUMERO" (Adjunto la rutina)
*----------------------------------------------------------------------------------------
DIMENSION laSubtotal[7]
laSubtotal[1] = 13 && D1A30
laSubtotal[2] = 14 && D31A60
laSubtotal[3] = 15 && D61A90
laSubtotal[4] = 16 && D91A120
laSubtotal[5] = 17 && D121A180
laSubtotal[6] = 18 && D181A360
laSubtotal[7] = 19 && DOVER360
#DEFINE xlSum -4157
oExcel = CREATEOBJECT("excel.application")
WITH oExcel
.Workbooks.OPEN(lcXLSFile)
WITH .ActiveWorkbook.ActiveSheet
lnRows = .UsedRange.ROWS.COUNT && Get current row count
.RANGE('M:S').NumberFormat = "#,##0.00" && Format columns
.UsedRange.Subtotal(1, xlSum, @laSubtotal)
.UsedRange.Subtotal(2, xlSum, @laSubtotal)
.UsedRange.Subtotal(3, xlSum, @laSubtotal)
.UsedRange.Subtotal(4, xlSum, @laSubtotal)
.UsedRange.Subtotal(5, xlSum, @laSubtotal)
.UsedRange.Subtotal(6, xlSum, @laSubtotal)
.UsedRange.Subtotal(7, xlSum, @laSubtotal,.F.,.F.,.F.)
.UsedRange.COLUMNS.AUTOFIT && Autofit columns
ENDWITH
.VISIBLE = .T.
ENDWITH
USE IN tmp3
***Pregunta 2:
Que debo de agregar para conseguir que me totalice por "CODIGO" (el cursor está ordenado por codigo)
Agradeciendo por su ayuda,
Atte,
Walter Salcedo
Lima-Perú