Exportar a Excel

Tengo un problemilla, yo filtro una vista con ciertos criterios, al dar un brow se ve la vusta filtrada, pero al exportar al excel me pasa siempre el primer dato de la tabal y no el dato filtrado, tengo k cerrar el excel y volver a exportar y recien me exporta los datos correctos. Mi codigo es algo asi:
SELE VCOLE
GO TOP
THISFORM.REFRESH
SET FILTER TO idalumno=Wcodigo
THISFORM.REFRESH
SELE VCER
local Fila
wait'Espere Un Momento Exportando Datos' window nowait
_screen.mousepointer=14
TmpSheet=CREATEOBJECT("Excel.Application")
XLApp=TmpSheet.Application
XLApp.visible=.T.
cFilename= "c:\certificado\datos1.xls"
XLApp.workbooks.Open(cFilename)
XLSheet=XLApp.ActiveSheet
XLSheet.Cells(14,3)=" " + THISFORM.TEXT2.VALUE
XLSheet.Cells(17,7)=Valum.AÑO1
XLSheet.Cells(17,8)=Valum.AÑO2
XLSheet.Cells(17,9)=Valum.AÑO3
XLSheet.Cells(17,10)=Valum.AÑO4
XLSheet.Cells(17,11)=Valum.AÑO5
y el asi sucesivamente.
ayuda plis y Gracias de Antemano
Respuesta
1
Espero poder ayudarte.
Yo no soy muy amigo de set filter to, prefiero el uso de la clausula for. El uso de set filter tiene mucha inestabilidad por el tema que las variables pueden cambiar por codigo o pueden quedar fuera de vista y otras cosas que pueden producir error en tu programa.
Si de igual manera queres usar el set filter yo retocaria tu código para que quede algo asi:
Sele vCole
SET FILTER TO idalumno=Wcodigo
wait'Espere Un Momento Exportando Datos' window nowait
_screen.mousepointer=14
TmpSheet=CREATEOBJECT("Excel.Application")
XLApp=TmpSheet.Application
XLApp.visible=.T.
cFilename= "c:\certificado\datos1.xls"
XLApp.workbooks.Open(cFilename)
XLSheet=XLApp.ActiveSheet
XLSheet.Cells(14,3)=" " + THISFORM.TEXT2.VALUE
fila=17
scan all
     XLSheet.Cells(fila,7)=Valum.AÑO1
     XLSheet.Cells(fila,8)=Valum.AÑO2
     XLSheet.Cells(fila,9)=Valum.AÑO3
     XLSheet.Cells(fila,10)=Valum.AÑO4
     XLSheet.Cells(fila,11)=Valum.AÑO5
     fila=fila+1
endscan
Como sugerencia, te propongo el uso de for en lugar de set filter
scan all for idalumno=Wcodigo
     XLSheet.Cells(fila,7)=Valum.AÑO1...
     fila=fila+1
Endscan
Bueno, espero que haya sido de utilidad mi respuesta
Estamos en contacto
Gracias por tu respuesta, pero sigue igual. Te voy a dar el codigo completo para k lo examines:
Primero: tengo varias vistas, es decir un alumno tiene: detalle de colegio, notas y asi por el estilo. todo el codigo esta en un boton. anteriormente de un list se elige el nombre a filtrar y pasa a un Text, tanto el codigo del alumno como el nombre.
ahi va:
Set filter to
SELE vcer
 GO TOP
 THISFORM.REFRESH
 Wcodigo=ALLT(THISFORM.Text1.VALUE)
 SET FILTER TO idalumno=Wcodigo
 THISFORM.REFRESH
SELE VCOLE
GO TOP
THISFORM.REFRESH
SET FILTER TO idalumno=Wcodigo
THISFORM.REFRESH
SELE Valum
GO TOP
THISFORM.REFRESH
SET FILTER TO idalumno=Wcodigo
THISFORM.REFRESH
SELE VCER
local Fila
wait'Espere Un Momento Exportando Datos' window nowait
_screen.mousepointer=14
TmpSheet=CREATEOBJECT("Excel.Application")
XLApp=TmpSheet.Application
XLApp.visible=.T.
cFilename= "c:\certificado\datos1.xls"
XLApp.workbooks.Open(cFilename)
XLSheet=XLApp.ActiveSheet
XLSheet.Cells(14,3)=" " + THISFORM.TEXT2.VALUE
XLSheet.Cells(17,7)=Valum.AÑO1
XLSheet.Cells(17,8)=Valum.AÑO2
XLSheet.Cells(17,9)=Valum.AÑO3
XLSheet.Cells(17,10)=Valum.AÑO4
XLSheet.Cells(17,11)=Valum.AÑO5
sele Vcole
XLSheet.Cells(19,13)=VCOLE.COLE1
XLSheet.Cells(19,14)=VCOLE.COLE2
XLSheet.Cells(19,15)=VCOLE.COLE3
XLSheet.Cells(19,16)=VCOLE.COLE4
XLSheet.Cells(30,13)=VCOLE.AÑO1
XLSheet.Cells(30,14)=VCOLE.AÑO2
XLSheet.Cells(30,15)=VCOLE.AÑO3
XLSheet.Cells(30,16)=VCOLE.AÑO4
Sele vAlum
XLSheet.Cells(50,5)="                        " + Valum.especialidad
XLSheet.Cells(51,5)="      " + Valum.mod3
XLSheet.Cells(52,5)="      " + Valum.mod4
XLSheet.Cells(53,5)="      " + Valum.mod5
Fila=19
cursos=19
SELE VCER
scan all
   XLSheet.Cells(Fila,7)=alltrim(VCER.LETRA1)
   XLSheet.Cells(Fila,8)=alltrim(VCER.LETRA2)
   XLSheet.Cells(Fila,9)=alltrim(VCER.LETRA3)
   XLSheet.Cells(Fila,10)=alltrim(VCER.LETRA4)
   XLSheet.Cells(Fila,11)=alltrim(VCER.LETRA5)
   XLSheet.Cells(cursos,5)=alltrim(VCER.nomcurso)
    Fila=Fila+1
    cursos=cursos+1
endscan
A VER K AOPNAS. GRACIAS DE ANTEMANO
Quedo un poquito mas chico el codigo.
Tené cuidado con tantos refresh y set filter, es una formula muy lenta
hacer go top antes de set filter no tiene efecto. Hacelo despues.
Sele vcer
wCodigo=ALLT(THISFORM.Text1.VALUE)
SET FILTER TO idalumno=wCcodigo
Go top
Sele vcole
SET FILTER TO idalumno=Wcodigo
Go top
SELE Valum
SET FILTER TO idalumno=Wcodigo
Go top
SELE VCER
Local Fila
wait'Espere Un Momento Exportando Datos' window nowait
_screen.mousepointer=14
TmpSheet=CREATEOBJECT("Excel.Application")
XLApp=TmpSheet.Application
XLApp.visible=.T.
cFilename= "c:\certificado\datos1.xls"
XLApp.workbooks.Open(cFilename)
XLSheet=XLApp.ActiveSheet
XLSheet.Cells(14,3)=" " + THISFORM.TEXT2.VALUE
XLSheet.Cells(17,7)=Valum.AÑO1
XLSheet.Cells(17,8)=Valum.AÑO2
XLSheet.Cells(17,9)=Valum.AÑO3
XLSheet.Cells(17,10)=Valum.AÑO4
XLSheet.Cells(17,11)=Valum.AÑO5
sele Vcole
XLSheet.Cells(19,13)=VCOLE.COLE1
XLSheet.Cells(19,14)=VCOLE.COLE2
XLSheet.Cells(19,15)=VCOLE.COLE3
XLSheet.Cells(19,16)=VCOLE.COLE4
XLSheet.Cells(30,13)=VCOLE.AÑO1
XLSheet.Cells(30,14)=VCOLE.AÑO2
XLSheet.Cells(30,15)=VCOLE.AÑO3
XLSheet.Cells(30,16)=VCOLE.AÑO4
Sele vAlum
XLSheet.Cells(50,5)=" " + Valum.especialidad
XLSheet.Cells(51,5)=" " + Valum.mod3
XLSheet.Cells(52,5)=" " + Valum.mod4
XLSheet.Cells(53,5)=" " + Valum.mod5
Fila=19
SELE VCER
scan all
XLSheet.Cells(Fila,7)=alltrim(VCER.LETRA1)
XLSheet.Cells(Fila,8)=alltrim(VCER.LETRA2)
XLSheet.Cells(Fila,9)=alltrim(VCER.LETRA3)
XLSheet.Cells(Fila,10)=alltrim(VCER.LETRA4)
XLSheet.Cells(Fila,11)=alltrim(VCER.LETRA5)
XLSheet.Cells(Fila,5)=alltrim(VCER.nomcurso)
Fila=Fila+1
endscan
De todas maneras, ya que las tablas estan indexadas por idAlumno te recomiendo hacer asi a ver que te parece:
wCodigo=ALLT(THISFORM.Text1.VALUE)
sele vcer
=seek(wCodigo)
SELE VCOLE
=seek(wCodigo)
SELE Valum
=seek(wCodigo)
SELE VCER
wait 'Espere Un Momento Exportando Datos' window nowait
_screen.mousepointer=14
TmpSheet=CREATEOBJECT("Excel.Application")
XLApp=TmpSheet.Application
XLApp.visible=.T.
cFilename= "c:\certificado\datos1.xls"
XLApp.workbooks.Open(cFilename)
XLSheet=XLApp.ActiveSheet
XLSheet.Cells(14,3)=" " + THISFORM.TEXT2.VALUE
XLSheet.Cells(17,7)=Valum.AÑO1
XLSheet.Cells(17,8)=Valum.AÑO2
XLSheet.Cells(17,9)=Valum.AÑO3
XLSheet.Cells(17,10)=Valum.AÑO4
XLSheet.Cells(17,11)=Valum.AÑO5
XLSheet.Cells(19,13)=VCOLE.COLE1
XLSheet.Cells(19,14)=VCOLE.COLE2
XLSheet.Cells(19,15)=VCOLE.COLE3
XLSheet.Cells(19,16)=VCOLE.COLE4
XLSheet.Cells(30,13)=VCOLE.AÑO1
XLSheet.Cells(30,14)=VCOLE.AÑO2
XLSheet.Cells(30,15)=VCOLE.AÑO3
XLSheet.Cells(30,16)=VCOLE.AÑO4
XLSheet.Cells(50,5)=" " + Valum.especialidad
XLSheet.Cells(51,5)=" " + Valum.mod3
XLSheet.Cells(52,5)=" " + Valum.mod4
XLSheet.Cells(53,5)=" " + Valum.mod5
Fila=19
SELE VCER
scan all for idAlumno=wCodigo
       XLSheet.Cells(Fila,7)=alltrim(VCER.LETRA1)
       XLSheet.Cells(Fila,8)=alltrim(VCER.LETRA2)
       XLSheet.Cells(Fila,9)=alltrim(VCER.LETRA3)
       XLSheet.Cells(Fila,10)=alltrim(VCER.LETRA4)
       XLSheet.Cells(Fila,11)=alltrim(VCER.LETRA5)
       XLSheet.Cells(Fila,5)=alltrim(VCER.nomcurso)
       Fila=Fila+1
Endscan
Amigo Cristian, Muchisimas Gracias por tu ayuda, ahora si sale creo k mucho refresh, ya estaba asustado, me has salvado la vida.
Otra Vez Muchas Gracias amigo Cristian. Tu respuesta estubo Excelente

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas