Exportar a excel con foxypreviewer

813 views
Skip to first unread message

MartinS

unread,
Aug 26, 2011, 12:39:41 AM8/26/11
to Comunidad de Visual Foxpro en Español
Buenas a todos,les comento que con foxypreviwer todo bigote (Bien),
pero ahora se me ha entrado la curiosidad de que si se puede desde los
datos que estan en un grid exportarlo directamente a excel osea desde
un boton exportar los datos de un grid a excel ?

Bueno, desde ya les agradezco.

Martin el papá de fiorella

Douglas Sánchez Guillén

unread,
Aug 26, 2011, 12:55:01 AM8/26/11
to publice...@googlegroups.com
Podes utilizar algo asi, espero te ubiques o extraigas lo elemental mi querido Watson

saludes...
*****
Wait Window At 10, 70 Nowait  "Espere un momento hasta que se carguen todos los registros..."
Local xalias As Cursor
xalias = Alias()
Goto Top
Public oexcel, xperido, xformato
xformato = '"##,###,###,##0.00"'
oexcel = Createobject("excel.application")
If Vartype(oexcel) <> "O"
= Messagebox( ;
"Microsoft excel no esta instalado...",0+16, "Alerta")
Return
Endif
oexcel.workbooks.Add()
oexcel.Visible = .T.
oexcel.cells(1, 2).Value = Upper(alcaldia.alcaldia)
oexcel.activesheet.usedrange.entirecolumn.AutoFit
oexcel.cells(2, 2).Value = "Presupuesto y Ejecución de Egresos por periodo   Año: " + xano
oexcel.Range(oexcel.cells(1, 1), oexcel.cells(4,7)).Select
oexcel.Range(oexcel.cells(1, 1), oexcel.cells(4, 7)).Font.bold = .T.
oexcel.Range(oexcel.cells(4, 1),oexcel.cells(4,7)).Font.Name ="Arial"
oexcel.Range(oexcel.cells(4, 1),oexcel.cells(4,7)).Font.Size = 12
oexcel.cells(5, 1).Value ="Código"
oexcel.cells(5, 2).Value = "Concepto de la cuenta"
oexcel.cells(5, 3).Value = "Pre.anual"
oexcel.cells(5, 4).Value = "Pre.periodo"
oexcel.cells(5, 5).Value = "Egr.periodo"
oexcel.cells(5, 6).Value =  "% Cum."
oexcel.cells(5, 7).Value = "Egr.acumulados"
oexcel.Range(oexcel.cells(5, 1),oexcel.cells(5, 7)).Select
oexcel.Range(oexcel.cells(5, 1),oexcel.cells(5,7)).Font.bold = .T.
oexcel.Range(oexcel.cells(5, 1),oexcel.cells(5,7)).Font.Name ="Arial"
oexcel.Range(oexcel.cells(5, 1), oexcel.cells(5, 7)).Font.Size = 9
oexcel.Selection.autoformat(2, .T., .T.,.T., .T., .T.,.T.)
oexcel.Rows("5:5").RowHeight = 20
oexcel.activesheet.usedrange.entirecolumn.AutoFit
oexcel.Range(oexcel.cells(5, 1), oexcel.cells(5,7)).horizontalalignment = - 4108
oexcel.Range(oexcel.cells(5, 1), oexcel.cells(5,7)).verticalalignment = -4108
Local desde, hasta As Integer
desde = 6
L = 6
Public tot1, tot2, tot3, tot4,tot5, tot6, tot7 As Number
Store 0.00  To tot3, tot4, tot5, tot7, tot9
Select &xalias
Scan
oexcel.cells(L, 1).Value = codigo
oexcel.cells(L, 2).Value = concepto
oexcel.cells(L, 3).Value = panual
oexcel.cells(L, 4).Value = pinicial
oexcel.cells(L, 5).Value = pejecutado
oexcel.cells(L, 6).Value = pc
oexcel.cells(L, 7).Value = pejecutado_a
If cabecera = 1
oexcel.cells(L,1).Font.bold = .T.
oexcel.cells(L,2).Font.bold = .T.
oexcel.cells(L,3).Font.bold = .T.
oexcel.cells(L,4).Font.bold = .T.
oexcel.cells(L,5).Font.bold = .T.
oexcel.cells(L,6).Font.bold = .T.
oexcel.cells(L,7).Font.bold = .T.
Else
tot3 = tot3 + panual
tot4 = tot4 + pinicial
tot5 = tot5 + pejecutado
tot7 = tot7 + pejecutado_a
Endif
L = L + 1
Select &xalias
Endscan
Select &xalias
If Eof()
L = L + 4
oexcel.cells(L, 2).Value = "Total gasto .............................................................C$ "
oexcel.cells(L, 3).Value = tot3
oexcel.cells(L, 4).Value = tot4
oexcel.cells(L, 5).Value = tot5
oexcel.cells(L, 7).Value = tot7
oexcel.cells(L, 2).Font.Size = 14
oexcel.cells(L, 3).Font.Size = 14
oexcel.cells(L, 4).Font.Size = 14
oexcel.cells(L, 5).Font.Size = 14
oexcel.cells(L, 7).Font.Size = 14
oexcel.cells(L, 2).Font.bold = .T.
oexcel.cells(L, 3).Font.bold = .T.
oexcel.cells(L, 4).Font.bold = .T.
oexcel.cells(L, 5).Font.bold = .T.
oexcel.cells(L, 7).Font.bold = .T.
Endif
hasta = L
oexcel.Range(oexcel.cells(5, 2), oexcel.cells(5,9)).Select
oexcel.activesheet.usedrange.entirecolumn.AutoFit
oexcel.activeworkbook.activesheet.Columns("B:B").ColumnWidth = 45
oexcel.Range(oexcel.cells(desde,1), oexcel.cells(hasta,9)).Font.Name = "Arial"
oexcel.Range(oexcel.cells(desde,1),oexcel.cells(hasta,9)).Font.Size = 8
oexcel.Range(oexcel.cells(6,3),oexcel.cells(hasta,7)).numberformat = &xformato
oexcel.activeworkbook.activesheet.pagesetup.leftheader = " "
oexcel.activeworkbook.activesheet.pagesetup.centerheader = Upper(alcaldia.alcaldia)
oexcel.activeworkbook.activesheet.pagesetup.RightHeader  = "Página: &P"
oexcel.activeworkbook.activesheet.pagesetup.RightFooter  = "Fecha de impresión: &D &T  dsg"
oexcel.activeworkbook.activesheet.pagesetup.leftfooter   = "Sistema de Presupuesto SISCO-INIFOM Central"
oexcel.activeworkbook.activesheet.pagesetup.printgridlines = .F.
oexcel.activeworkbook.activesheet.pagesetup.centerhorizontally = .T.
oexcel.activeworkbook.activesheet.pagesetup.centervertically = .F.
oexcel.activeworkbook.activesheet.pagesetup.Orientation =  1
oexcel.activeworkbook.activesheet.pagesetup.Papersize = 1
oexcel.activeworkbook.activesheet.pagesetup.printarea = "$A:$K"
oexcel.activeworkbook.activesheet.pagesetup.printtitlerows = "$1:$7"
oexcel.activeworkbook.activesheet.pagesetup.Zoom = 69
oexcel.activeworkbook.printpreview
Wait Window At 10, 70 Timeout 0.5 "listo"
Wait Clear
oexcel = .Null.
Release tot1, tot2, tot3, tot4,tot5, tot6, tot7, oexcel

******

--
Ing. Douglas Sánchez Guillén
      Consultor Informatico
Movistar: 505 8759 - 5342
Claro: 505 88495476

Cesar VfpImaging

unread,
Aug 26, 2011, 1:12:30 AM8/26/11
to publice...@googlegroups.com
Gracias Douglas
 
Martin, FoxyPreviewer es un aplicativo somente para trabajar con reportes. El utiliza la clase ReportListener, que converte las informaciones de un reporte para Excel, PDF, etc.
Si quieres hacerlo con FoxyPreviewer, hay que crear un reporte, y utilizar el comando REPORT FORM.
 
Lo mas facil es utilizar la sugerencia de Douglas
 
Saludos


 
2011/8/26 Douglas Sánchez Guillén <dougl...@gmail.com>

MartinS

unread,
Aug 26, 2011, 1:31:39 AM8/26/11
to Comunidad de Visual Foxpro en Español
Mil disculpas por haberlos molestado pero hace un tiempo atras ya
habia hecho la misma pregunta y me respondio luis mata con el
siguiente codigo y funsiona :

SET PROCEDURE TO LOCFILE("FoxyPreviewer.App") ADDITIVE
LOCAL loReport as "PreviewHelper" OF "FoxyPreviewer.App"
loReport = CREATEOBJECT("PreviewHelper")
WITH loReport as ReportHelper
.AddReport("&lcreport","NODIALOG")
*.cDestFile = "c:\&lcreport" &&"c:\Teste1.xls" && Use to
create an output without previewing
.cDestFile = "c:\Teste1.xls" && Use to create an output
without previewing
.RunReport()
ENDWITH
loReport = NULL
*RUN /N Explorer.Exe c:\Teste1.pdf

gracias por su atencion

Cesar VfpImaging

unread,
Aug 26, 2011, 2:02:40 AM8/26/11
to publice...@googlegroups.com
PEro el codigo funciona si tienes un REPORTE !!!
No es para transferir directamente de una grid !

2011/8/26 MartinS <marti...@gmail.com>
Reply all
Reply to author
Forward
0 new messages