Reporte en Excel con automatizacion muy lento

765 views
Skip to first unread message

Carlos Alfaro

unread,
Mar 6, 2013, 10:10:32 AM3/6/13
to publice...@googlegroups.com

Saludos amigos foxeros:

 

Un cliente me pidió que busque como acelerar un reporte que se exporta a Excel, ya que tarda mucho, la computadora que usan es potente.

 

Hice pruebas en mi computadora en un disco virtual con VirtualBox y al exportar a Excel por medio de automatización, tarda 2 segundos por registro.

 

Usando el administrador de tareas vi que el procesador se satura.

 

El código es muy sencillo:

 

GO TOP

DO WHILE !EOF()

  oleExcel.cells.cells(nRen,1)  = ALLTRIM(dia)

  oleExcel.cells.cells(nRen,2)  = 'WEEK ' + ALLTRIM(semana)

  oleExcel.cells.cells(nRen,3)  = DTOC(teni_fecha)

  oleExcel.cells.cells(nRen,4)  = 'MES'

  oleExcel.cells.cells(nRen,5)  = ALLTRIM(po)

  oleExcel.cells.cells(nRen,6)  = 'M1'

  oleExcel.cells.cells(nRen,7)  = ALLTRIM(bd_style)

  oleExcel.cells.cells(nRen,8)  = ALLTRIM(STR(bd_pound))

  oleExcel.cells.cells(nRen,9)  = ALLTRIM(rib_style)

  oleExcel.cells.cells(nRen,10) = IIF(rib_pound > 0,ALLTRIM(STR(rib_pound)),'')

  oleExcel.cells.cells(nRen,11) = ALLTRIM(xtra_style)

  oleExcel.cells.cells(nRen,12) = IIF(xtra_pound > 0,ALLTRIM(STR(xtra_pound)),'')

  oleExcel.cells.cells(nRen,14) = ALLTRIM(color_ord)

  oleExcel.cells.cells(nRen,15) = ALLTRIM(cut_plant)

  oleExcel.cells.cells(nRen,16) = ALLTRIM(maq_nomb)

  oleExcel.cells.cells(nRen,17) = ALLTRIM(turno)

  nRen = nRen + 1

  SKIP

ENDDO

 

Agradeciendo su atencion y comentarios.

 

Bendiciones.

 

Carlos Alfaro

Luis Maria Guayan

unread,
Mar 6, 2013, 10:22:54 AM3/6/13
to publice...@googlegroups.com
En estos casos si se exportan muchos registros, mejor es hacer un COPY TO ... TYPE XL5 y una vez copiado, abrir la planilla con automatización y allí agregarle los títulos, darle el formato a las filas y columnas, y toda la cosmética que necesites.


Luis María Guayán
Tucumán, Argentina
_________________________
http://www.PortalFox.com
Nada corre como un zorro
_________________________

Carlos Alfaro

unread,
Mar 6, 2013, 11:17:30 AM3/6/13
to publice...@googlegroups.com

Gracias amigo Luis Ma.:

 

Eso voy a hacer.

 

Bendiciones.

 

Carlos Alfaro

Hernandez Gabriel

unread,
Mar 6, 2013, 11:20:51 AM3/6/13
to publice...@googlegroups.com
Hola, te coloco un pequeño ejemplo de como lo hago Yo, espero te sirva. Saludos

if used("VerCiudades")
try
SELECT VerCiudades
GO top
EXPORT TO SYS(5)+CURDIR()+"informes\Ciudades" TYPE XL5 FIELDS orden, ciudad 

**** COLOCAR ENCABEZADO DEL EXCEL
LOCAL i,j,TrendFunc,xlsheet,XLApp,tmpsheet

XLAPP = Createobject("Excel.Application")
IF TYPE("XlApp")="O"

a=SYS(5)+CURDIR()+"informes\Ciudades.xls" 

XLApp.WorkBooks.add(a)
XLSheet = XLApp.ActiveSheet

XLApp.APPLICATION.activeworkbook.activesheet.cells(1,1).SELECT
XLApp.APPLICATION.activeworkbook.activesheet.cells(1,1).value="Orden"
XLApp.APPLICATION.activecell.FONT.SIZE = 11
XLApp.APPLICATION.activecell.FONT.Bold = .F.
XLApp.APPLICATION.activecell.FONT.Italic = .F.
XLApp.APPLICATION.activecell.Interior.ColorIndex = 15
XLApp.APPLICATION.activecell.Interior.PATTERN = 1

XLApp.APPLICATION.activeworkbook.activesheet.cells(1,2).SELECT
XLApp.APPLICATION.activeworkbook.activesheet.cells(1,2).value="Ciudad"
XLApp.APPLICATION.activecell.FONT.SIZE = 11
XLApp.APPLICATION.activecell.FONT.Bold = .F.
XLApp.APPLICATION.activecell.FONT.Italic = .F.
XLApp.APPLICATION.activecell.Interior.ColorIndex = 15
XLApp.APPLICATION.activecell.Interior.PATTERN = 1

FOR i=1 TO 4
XLSheet.Rows("1:1").Insert
ENDFOR

***** combinar celdas para el logo
XLApp.APPLICATION.activeworkbook.activesheet.range("A1:B2").SELECT
XLApp.APPLICATION.activeworkbook.activesheet.range("A1:B2").Merge

***** combinar celdas para los datos de la empresa
XLApp.APPLICATION.activeworkbook.activesheet.range("C1:D2").SELECT
XLApp.APPLICATION.activeworkbook.activesheet.range("C1:D2").Merge

***** combinar celdas para el titulo del imforme
XLApp.APPLICATION.activeworkbook.activesheet.range("A3:D3").SELECT
XLApp.APPLICATION.activeworkbook.activesheet.range("A3:D3").Merge

***** cambiar tamaño de la celda para el logo
XLApp.APPLICATION.activeworkbook.activesheet.range("A1:D1").SELECT
XLSheet.Rows(1).RowHeight=50

***** cambiar tamaño de la celda para el titulo
XLApp.APPLICATION.activeworkbook.activesheet.range("A3:I3").SELECT
XLSheet.Rows(3).RowHeight=20

***** colocamos el titulo
XLApp.APPLICATION.activeworkbook.activesheet.cells(3,1).SELECT
XLApp.APPLICATION.activeworkbook.activesheet.cells(3,1).value="Listado de Ciudades"
XLApp.APPLICATION.activecell.FONT.SIZE = 16
XLApp.APPLICATION.activecell.FONT.Bold = .T.
XLApp.APPLICATION.activecell.FONT.Italic = .T.
XLApp.APPLICATION.activecell.HorizontalAlignment=-4108

***** colocamos el logo
XLApp.APPLICATION.activeworkbook.activesheet.cells(1,1).SELECT
XLSheet.Pictures.Insert(sys(5)+curdir()+"temp\logo.png").name="Logo"
XLSheet.Shapes("Logo").Top =0
XLSheet.Shapes("Logo").Left =0


 TEXT TO datosempresax NOSHOW ADDITIVE TEXTMERGE PRETEXT 7
    <<datosempresa>>    
   ENDTEXT

***** colocamos los datos de la empresa    
XLApp.APPLICATION.activeworkbook.activesheet.range("C1:C1").SELECT
XLApp.APPLICATION.activeworkbook.activesheet.range("C1:C1").VALUE=datosempresax
XLApp.APPLICATION.activecell.FONT.SIZE = 10
XLApp.APPLICATION.activecell.FONT.Bold = .F.
XLApp.APPLICATION.activecell.FONT.Italic = .F.
XLApp.APPLICATION.activecell.HorizontalAlignment=-4152
XLApp.APPLICATION.activecell.VerticalAlignment=-4107

**** nos situamos en la primera celda con formato
XLApp.APPLICATION.activeworkbook.activesheet.cells(5,1).SELECT

XLApp.COLUMNS.AUTOFIT


_SCREEN.oRibbon.MESSAGEBOX("SE HAN EXPORTADO LOS DATOS." ,"16" ,"ATENCIÓN" ,"Aceptar" ,"ABOUT32.PNG" ,0)

 
XLApp.Visible = .T. 
RELEASE XLApp

ELSE
_SCREEN.oRibbon.MESSAGEBOX("No tiene instalado Excel o no está registrado correctamente." ,"16" ,"FALTAN DATOS" ,"Aceptar" ,"ABOUT32.PNG" ,0)
 
ENDIF



catch

_SCREEN.oRibbon.MESSAGEBOX("NO HAY DATOS PARA EXPORTAR." ,"16" ,"ATENCIÓN" ,"Aceptar" ,"ABOUT32.PNG" ,0)
ENDTRY


else
_SCREEN.oRibbon.MESSAGEBOX("NO HAY DATOS PARA EXPORTAR." ,"16" ,"ATENCIÓN" ,"Aceptar" ,"ABOUT32.PNG" ,0)


ENDIF

Riago

unread,
Mar 6, 2013, 3:45:25 PM3/6/13
to publice...@googlegroups.com
Hola Carlos
Si utilizas COPY TO...TYPE XLS o EXPORT tienes que tener en cuenta que solo aceptan hasta 65535 registros. Yo utilicé la clase de Walter Ojeda y copió relativamente rapido pero el limite de excell es 1.048.000 y un poquito. Te hago el comentario por si lo que necesitas es volumen.

Un abrazo
Ricardo Gonzalez


miltonvas

unread,
Mar 6, 2013, 5:53:45 PM3/6/13
to publice...@googlegroups.com
y si el numero de registros es mayor a 16384 entocnes es mejor hacer COPY TO ...... TYPE FOX2X
yo lo he probado hasta con un millon de registros y se abre rapido en excel 

Carlos Alfaro

unread,
Mar 6, 2013, 6:39:02 PM3/6/13
to publice...@googlegroups.com
Gracias amigo Riago:

Son aproximadamente 700 registros, pero multiplicados por 2 segundos cada uno son como 23 minutos.

Bendiciones.

Carlos Alfaro

-----Original Message-----
From: publice...@googlegroups.com [mailto:publice...@googlegroups.com] On Behalf Of Riago
Sent: miércoles, 06 de marzo de 2013 02:45 p.m.
To: publice...@googlegroups.com
Subject: Re: [vfp] Reporte en Excel con automatizacion muy lento

Carlos Alfaro

unread,
Mar 6, 2013, 6:41:37 PM3/6/13
to publice...@googlegroups.com

Interesante amigo Gabriel:

 

Muchas gracias.

 

Bendiciones.

 

Carlos Alfaro

FidelJ

unread,
Mar 6, 2013, 7:40:46 PM3/6/13
to publice...@googlegroups.com, calf...@yahoo.com.ar
Aunque el siguiente código no se adapta exactamente a lo requerido, tiene mejor performance. Por ejemplo, una tabla de 2670 registros tarda algo así como 19 segundos en una Pentium IV 2.80 con XP.
Las diferencias pueden estar en el uso de With / Endwith y oExcel.Cells(nren,i_).Value=(valor de celda)
Adaptando la idea a tu necesidad, puede funcionar. No he considerado acá formatos de presentación.
El uso de SCAN ENDSCAN en lugar de Do While !Eof(), es recomendable, aunque en este caso no ha de representar nada en materia de tiempo.

* Método DbfExcel
LPARAMETERS xcFile,xcListaCampos,xcListaHeader
* xcFile= Tabla o cursor
* xcListaCampos= Campos a listar separado por comas. (Omite=Todos)
* xcListaHeader= Encabezados de columnas (Omite=xcLlistaCampos)
* .DbfExcel(cTabla,cListaCampos,cListaHeader)
*------------------------------------------------------------------
LOCAL minfeval,i,i_,lpag,r,cCampo,cValprop,cVarType,bDezim

minfeval=Ctod("01/01/1900")
WAIT WINDOW " Exportando tabla "+Versales(xcfile) at 12,15 nowait

Oexcel = CREATEOBJECT("Excel.Application")
IF TYPE('Oexcel')#'O'
release mensajero
=MESSAGEBOX("No se puede procesar el archivo porque no tiene la aplicación"+CHR(13)+;
     "Microsoft Excel instalada en su computador.",0,tH_mensaje)
RETURN .F.
ENDIF

lPag=1
xLApp = Oexcel
kelibro=XLApp.workbooks.ADD()
XLSheet = XLApp.ActiveSheet
XLSheet.NAME=Versales(xcFile)+'_'+ALLTR(STR(lpag))
HojaName=Versales(xcFile)+'_'+ALLTR(STR(lpag))

SELECT (xcFile)
AFIELDS(gastruc)
IF EMPTY(xcListaCampos)
LOCAL ARRAY gaCampos(ALEN(gastruc,1))
FOR i=1 TO ALEN(gastruc,1)
gaCampos=gastruc[i,1]
NEXT
ELSE
nCampos=ALINES(gaCampos,UPPER(ALLTRIM(xcListaCampos)),1,",")
ENDIF
IF EMPTY(xcListaHeader)
LOCAL ARRAY gaHeader(ALEN(gaCampos))
FOR i=1 TO ALEN(gaCampos)
gaHeader[i]=PROPER(gaCampos[i])
NEXT
ELSE
nHeaders=ALINES(gaHeader,xcListaHeader,1,",")
FOR i=1 TO nHeaders
gaheader[i]=PROPER(gaHeader[i])
NEXT
ENDIF

lcExact=SET("Exact")
SET EXACT ON
r=1
FOR i_=1 TO ALEN(gaHeader)
with xlSheet.Cells(r,i_)
.Value=ALLTRIM(gaHeader[i_])
.Font.Bold=.t.
ENDWITH
next
r=r+1

SCAN
FOR i_=1 TO ALEN(gaCampos)
cCampo=gaCampos[i_]
cValRep=EVALUATE(cCampo)
nas=ASCAN(gaStruc,cCampo)
IF nas=0
LOOP  && Error en xcListaCampos
ENDIF
cVartype=gastruc[nas+1]
bDezim=gastruc[nas+3]

IF !cVarType$'GQ'
with xlSheet.Cells(r,i_)
        DO CASE
        CASE cVartype="C"
        .Value=ALLTRIM(cValRep)
       
        CASE cVartype="N"
        cNumform=iif(bdezim=0,"#,##0","#,##0.")+Repli("0",bDezim)
.Style.IncludeNumber =.T.
        .NumberFormat=cNUmForm
.VALUE=cValrep
        CASE cVartype="D"
        if cValrep<minfeval
        cValrep=Ctod("")
        endif
        IF !EMPTY(cValrep)
.VALUE=cValrep
endif
        CASE cVartype="T"
           .VALUE=TTOC(cValrep)
        OTHERWISE
        .VALUE=cValrep
       
 
        ENDCASE
endwith
ENDIF
NEXT

R=R+1
ENDSCAN
SET EXACT &lcExact
WAIT clear
Oexcel.VISIBLE=.T.


gmail

unread,
Mar 7, 2013, 4:10:14 AM3/7/13
to publice...@googlegroups.com
yo uso esta forma
 

Local

cErrores, lExcel,oExcel

** BUSCO UNA SESION DE EXCEL YA ACTIVA

*nRows se usa para los registro o fila

Wait Window

"Espere... Exportandos datos" Nowait

cErrores =

On("ERROR")

On Error

lExcel = .F.

oExcel =

Getobject(,"excel.application")

On Error

&cErrores

oExcel =

Createobject("Excel.Application")

oExcel.

Visible = .T. && VISUALIZO EXCEL

oExcel.Workbooks.

Add && PREPARO UN NUEVO TRABAJO DE EXCEL

oExcel.ActiveWindow.

Zoom = 95 && Zoom

** Empiezo a carga los datos correspondiente en la hoja de excel

** Nombre de la planilla o hoja1 de excel

oExcel.Sheets("Hoja1").

Name = "Movimientos General" &&Nombre de la hoja

 

** Crea el Formato de la Hoja

** Formato general de la hoja

WITH

oExcel.Cells.Font

 

.Name = "Tahoma"

.

Size = 8

ENDWITH

** Tamaño para las columnas

WITH

oExcel

.

Columns("A:A").ColumnWidth = 11

.

Columns("B:B").ColumnWidth = 9

.

Columns("C:C").ColumnWidth = 9

.

Columns("D:D").ColumnWidth = 60

.

Columns("E:J").ColumnWidth = 8

 

*.Columns("F:J").ColumnWidth = 10

*.Columns("G:H").ColumnWidth = 11

*.Columns("I:I").ColumnWidth = 10

*.Columns("J:J").ColumnWidth = 12

ENDWITH

 

** Rectangulo para los titulos

_bor = 3

WITH

oExcel.Range(oExcel.Cells(3,1), oExcel.Cells(3,8))

.Borders(01).Weight = _bor

.Borders(02).Weight = _bor

.Borders(03).Weight = _bor

.Borders(04).Weight = _bor

.Borders(07).Weight = _bor

.Borders(08).Weight = _bor

.Borders(09).Weight = _bor

.Borders(10).Weight = _bor

ENDWITH

 

 

** Mensaje

nRows = 1

oExcel.Cells(nRows,1) = "SysGes exportando datos. Por favor Espere....."

** Para la fecha

_f1 = _f1 + 1

&&DESDE

_f2 = _f2 - 1

&&HASTA

nRows = 2

oExcel.Cells(nRows,1) =

ALLTRIM(DTOC(_f1))+ " al " + ALLTRIM(DTOC(_f2))

 

** Título de los campos

nRows = 3

oExcel.Cells(nRows,1) = "Tipo de mov."

oExcel.Cells(nRows,2) = "Fecha"

oExcel.Cells(nRows,3) = "Nº de Mov."

oExcel.Cells(nRows,4) = "Detalle del movimiento"

oExcel.Cells(nRows,5) = "Cantidad"

oExcel.Cells(nRows,6) = "Precio"

oExcel.Cells(nRows,7) = "Debe"

oExcel.Cells(nRows,8) = "Haber"

 

 

 

** Formato para el Título

WITH

oExcel.Range(oExcel.Cells(1, 1), oExcel.Cells(1,8)) &&combina desde la columna 1 hasta 8

 

.HorizontalAlignment = 3

.MergeCells = .T.

.

Font.Bold = .T.

.

Font.ColorIndex = 5

.

Font.Size = 14

ENDWITH

** Formato para la fecha (desde al hasta)

WITH

oExcel.Range(oExcel.Cells(2, 1), oExcel.Cells(2,8)) &&combina desde la columna 1 hasta 8

 

.HorizontalAlignment = 3

.MergeCells = .T.

.

Font.Bold = .T.

.

Font.ColorIndex = 5

.

Font.Size = 10

ENDWITH

 

** Formato columna tipo de movimiento

WITH

oExcel.Range(oExcel.Cells(3,1), oExcel.Cells(3,1))

.HorizontalAlignment = 3

.MergeCells = .T.

.

Font.Bold = .T.

.

Font.ColorIndex = 5

.

Font.Size = 8

ENDWITH

 

** Formato columna fecha

WITH

oExcel.Range(oExcel.Cells(3,2), oExcel.Cells(3,2))

.HorizontalAlignment = 3

.MergeCells = .T.

.

Font.Bold = .T.

.

Font.ColorIndex = 5

.

Font.Size = 8

ENDWITH

** Formato columna Nº de mov.

WITH

oExcel.Range(oExcel.Cells(3,3), oExcel.Cells(3,3))

.HorizontalAlignment = 3

.MergeCells = .T.

.

Font.Bold = .T.

.

Font.ColorIndex = 5

.

Font.Size = 8

ENDWITH

 

** Formato columna Descripción de movimiento

WITH

oExcel.Range(oExcel.Cells(3,4), oExcel.Cells(3,4))

.HorizontalAlignment = 3

.MergeCells = .T.

.

Font.Bold = .T.

.

Font.ColorIndex = 5

.

Font.Size = 8

ENDWITH

 

** Formato columna Cantidad

WITH

oExcel.Range(oExcel.Cells(3,5), oExcel.Cells(3,5))

.HorizontalAlignment = 3

.MergeCells = .T.

.

Font.Bold = .T.

.

Font.ColorIndex = 5

.

Font.Size = 8

ENDWITH

** Formato columna Precio

WITH

oExcel.Range(oExcel.Cells(3,6), oExcel.Cells(3,6))

.HorizontalAlignment = 3

.MergeCells = .T.

.

Font.Bold = .T.

.

Font.ColorIndex = 5

.

Font.Size = 8

ENDWITH

** Formato columna Debe

WITH

oExcel.Range(oExcel.Cells(3,7), oExcel.Cells(3,7))

.HorizontalAlignment = 3

.MergeCells = .T.

.

Font.Bold = .T.

.

Font.ColorIndex = 5

.

Font.Size = 8

ENDWITH

** Formato columna Haber

WITH

oExcel.Range(oExcel.Cells(3,8), oExcel.Cells(3,8))

.HorizontalAlignment = 3

.MergeCells = .T.

.

Font.Bold = .T.

.

Font.ColorIndex = 5

.

Font.Size = 8

ENDWITH

 

** Empiezo a cargar campo por campo en la hoja de excel

Select

mov_gral

Scan

 

nRows = nRows + 1

 

For nColumn = 1 To 8

 

 

If nColumn = 1 && tipo de mov

 

IF mov_gral.Tipo > " "

oExcel.Cells(nRows,nColumn) = mov_gral.Tipo

 

endif

ENDIF

If

nColumn = 2 && fecha del movimiento

 

IF mov_gral.fecha <> {}

oExcel.Cells(nRows,nColumn) = mov_gral.fecha

 

endif

ENDIF

 

If

nColumn = 3 && Código de los movimiento

 

IF mov_gral.codigo > 0

oExcel.Cells(nRows,nColumn) = mov_gral.codigo

 

endif

ENDIF

 

If

nColumn = 4 && descripcion

 

oExcel.Cells(nRows,nColumn) = ALLTRIM(mov_gral.descripcion)

 

ENDIF

 

If

nColumn = 5 && Cantidad

 

IF mov_gral.Cantidad > 0

oExcel.Cells(nRows,nColumn) = mov_gral.Cantidad/100

 

endif

ENDIF

 

If

nColumn = 6 && precio

 

IF mov_gral.precio > 0

oExcel.Cells(nRows,nColumn) = mov_gral.precio

 

endif

ENDIF

 

If

nColumn = 7 && Haber

 

IF mov_gral.totalsal > 0

oExcel.Cells(nRows,nColumn) = mov_gral.totalsal

 

endif

ENDIF

 

If

nColumn = 8 && Debe

 

IF mov_gral.TotalEnd > 0

oExcel.Cells(nRows,nColumn) = mov_gral.TotalEnd

 

endif

ENDIF

 

Next

nColumn

Endscan

** Calculando el total de la entrada y salida del cursor de movimiento

SELECT SUM

(TotalSal) salida , SUM(TotalEnd) entrada FROM mov_gral INTO CURSOR cur_total

** Inserto el total de la salida y entrada

nRows = nRows + 2

oExcel.Cells(nRows,4) = " TOTALES:"

oExcel.Cells(nRows,7) = cur_total.salida

oExcel.Cells(nRows,8) = cur_total.entrada

** Fin

** Para el log del programa

nRows = nRows + 2

oExcel.Cells(nRows,4) = "Generado por SysGes - Sistema de Gestión"

**

** Otros formato

** Formato General para las columnas: precio, debe, haber

oExcel.

Range(oExcel.Cells(4,8), oExcel.Cells(nRows,4)).NumberFormat = '#,##'

** Formato para la columna cantidad

oExcel.

Range(oExcel.Cells(5,5), oExcel.Cells(nRows,4)).NumberFormat = '#,##.00'

**

 

** Formato columna Descripción de movimiento

WITH

oExcel.Range(oExcel.Cells(nRows,4), oExcel.Cells(nRows,4))

.HorizontalAlignment = 3

.MergeCells = .T.

.

Font.Bold = .T.

.

Font.ColorIndex = 5

.

Font.Size = 8

ENDWITH

 

** Formato columna Debe

WITH

oExcel.Range(oExcel.Cells(nRows,7), oExcel.Cells(nRows,7))

.HorizontalAlignment = 3

.MergeCells = .T.

.

Font.Bold = .T.

.

Font.ColorIndex = 5

.

Font.Size = 8

ENDWITH

** Formato columna Haber

WITH

oExcel.Range(oExcel.Cells(nRows,8), oExcel.Cells(nRows,8))

.HorizontalAlignment = 3

.MergeCells = .T.

.

Font.Bold = .T.

.

Font.ColorIndex = 5

.

Font.Size = 8

ENDWITH

 

 

** Formato para el Título

x = 1

&&Se usa para la fila

oExcel.Cells(x,1) = "Movimiento General"

WITH

oExcel.Range(oExcel.Cells(1, 1), oExcel.Cells(1,8)) &&combina desde la columna 1 hasta 8

 

.HorizontalAlignment = 3

.MergeCells = .T.

.

Font.Bold = .T.

.

Font.ColorIndex = 5

.

Font.Size = 14

ENDWITH

 

** Preparando vista previa

WITH

oExcel.ActiveSheet.PageSetup

.PrintArea = "$A$1:$J$" +

ALLTRIM(STR(nRows + 2))

.PrintTitleRows = "$1:$9"

.PrintTitleColumns = ""

.

Zoom = .f.

.FitToPagesWide = 1

.FitToPagesTall = 100

.Orientation = 1

.PaperSize = 1

 

*.CenterFooter ="COT. " + ALLTRIM(rpcab.nombre)

*.RightFooter = "Página &P"

ENDWITH

*oExcel.ActiveWindow.SelectedSheets.PrintPreview

h = "SysGes" +" - "+

Wtitle()

Messagebox

("Exportación de datos completados","&h")
Orgware
Orgware

Miguel Antúnez

unread,
Mar 7, 2013, 7:34:20 AM3/7/13
to publice...@googlegroups.com
Esta es otra forma de enviar datos a Excel.

PUBLIC oXls     
oXls = CREATEOBJECT(“excel.application”)
oXls.Workbooks.Add
oXls.Visible = .T.

SELECT * FROM ‘Tu Tabla’ INTO CURSOR cursorXls && No es necesario pasarlo a un cursor
_Vfp.DataToClip (‘cursorXls’,,3)  && Copiar el cursor a memoria
oXls.Cells(1,1).Select     && Seleccionar el Inicio de la Copia de los Datos
oXls.ActiveSheet.Paste()    && Copiar los datos al Excel
_Cliptext = ”      && Para liberar la memoria
USE IN (SELECT(‘cursorXls’))   && Cerrar el cursor

Saludos.



--
Miguel Angel Antúnez Camones
mant...@gmail.com

Carlos Alfaro

unread,
Mar 7, 2013, 8:18:15 AM3/7/13
to publice...@googlegroups.com

Muchas gracias amigos fidel, mangomez y Miguel:

 

Son muy interesantes sus propuestas.

 

Espero mañana ir a donde el cliente y aplicar sus sugerencias.

 

Que Dios les bendiga.

 

Carlos Alfaro

 

From: publice...@googlegroups.com [mailto:publice...@googlegroups.com] On Behalf Of Miguel Antúnez


Sent: jueves, 07 de marzo de 2013 06:34 a.m.
To: publice...@googlegroups.com

Daniel Sánchez

unread,
Mar 7, 2013, 12:19:00 PM3/7/13
to Comunidad de Visual Foxpro en Español
La mejor y más rápida opción es la de Miguel Antunez, yo también lo hago así solo formateo los títulos le doy color marcos pero el cuerpo lo acumulo en una variable luego lo paso _cliptext y finalmente le doy un paste en el excel y eso lo hace en segundos sin importar mucho la cantidad de filas a enviar.

Saludos
--
Daniel Sánchez Escobar
Investigación y Desarrollo
Reset Software & Sistemas
Móvil +051-949398047
Trujillo - Perú
Reply all
Reply to author
Forward
0 new messages