Automatizacion con OpenOffice

353 views
Skip to first unread message

apzavaleta

unread,
Jul 22, 2011, 5:27:58 PM7/22/11
to Comunidad de Visual Foxpro en Español
Hola comunidad Foxera!!

Actualmente tengo algunos reportes con automatización hacia excel y
word, pero quisiera hacer lo mismo con la Suite de OpenOfice, alguien
me puede recomendar un buen manual, tutoreal o algo por el estilo.

Salu2!!

Edgar Acevedo

unread,
Jul 22, 2011, 5:42:36 PM7/22/11
to publice...@googlegroups.com
Te adjunto un documento que arroja "algunas luces" sobre el asunto.
Manejando OpenOffice desde Fox.doc

Edgar Acevedo

unread,
Jul 22, 2011, 5:50:38 PM7/22/11
to publice...@googlegroups.com
Te adjunto un ejemplo del código que utilizo para enviar un listado de cheques de una tabla llamada MovBancos hacia una hoja de cálculo  de  OpenOffice (Calc). Estoy utilizando aquí,  OpenOffice 3.3

* Toda esta parte es prácticamente solo para Instanciar un Objeto de  OpenOffice  Calc
* Se podría decir que siempre tendrás que usarla de esta forma

oServOO = CREATEOBJECT("Com.Sun.Star.ServiceManager.1")
oPlatOO = oServOO.CreateInstance("com.sun.star.frame.Desktop")
*!* COMARRAY(oServOO, 10)

oReflectX = oServOO.createInstance("com.sun.star.reflection.CoreReflection")
*!* COMARRAY(oReflectX, 10)

oValorP = CREATEOBJECT("Relation")
oReflectX.forName("com.sun.star.beans.PropertyValue").CreateObject(@oValorP)

DIMENSION aProp(1)
aProp[1] = oValorP
aProp[1].Name = "ReadOnly"
aProp[1].Value = .F.

oDoc = oPlatOO.LoadComponentFromURL("private:factory/scalc", "_blank", 0, @aProp)
oHoja = oDoc.getSheets.getByName("Hoja1")

* Desde aquí comienza el código que pone títulos, formatea columnas y escribe los datos en la hoja

oHoja.SetPropertyValue("CharFontName", "Lucida Console")
oHoja.getCellByPosition( 0, 0 ).setString("ABDT")
oHoja.getCellByPosition( 0, 0 ).setPropertyValue("CharHeight", 22)
oHoja.getCellByPosition( 0, 1 ).setString("Consulta de Cheques Operados")
oHoja.getCellByPosition( 0, 1 ).setPropertyValue("CharHeight", 18)

IF EMPTY(M.FilEmp)
   oHoja.getCellByPosition( 0, 2 ).setString("Cheques de TODAS las empresas.")
ELSE
   SET ORDER TO CODEMP IN EMPRESAS
   IF SEEK(M.FilEmp, 'EMPRESAS')
      M.INSTRU = 'oHoja.getCellByPosition( 0, 2 ).setString("Solo cheques de ' + M.FilEmp + '-' + EMPRESAS.NomEmp + '")'
      &INSTRU
   ELSE
      M.INSTRU = 'oHoja.getCellByPosition( 0, 2 ).setString("Solo cheques de ' + M.FilEmp + '")'
      &INSTRU
   ENDIF
ENDIF
oHoja.getCellByPosition( 0, 2 ).setPropertyValue("CharHeight", 14)

IF EMPTY(M.FilCbn)
   oHoja.getCellByPosition( 0, 3 ).setString("Cheques de TODAS las cuentas bancarias.")
ELSE
   SET ORDER TO CODCBN IN CHEQUERAS
   IF SEEK(M.FilCbn, 'CHEQUERAS')
      M.INSTRU = 'oHoja.getCellByPosition( 0, 3 ).setString("Cheques de ' + M.FilCbn + ' / ' + ALLTRIM(CHEQUERAS.NumCbn) + ' - ' + CHEQUERAS.NomCbn + '")'
      &INSTRU
   ELSE
      M.INSTRU = 'oHoja.getCellByPosition( 0, 3 ).setString("Solo cheques de ' + M.FilCbn + '")'
      &INSTRU
   ENDIF
ENDIF
oHoja.getCellByPosition( 0, 3 ).setPropertyValue("CharHeight", 14)

IF EMPTY(M.FilDes)
   oHoja.getCellByPosition( 0, 4 ).setString("Cheques de CUALQUIER fecha.")
ELSE
   M.INSTRU = 'oHoja.getCellByPosition( 0, 4 ).setString("Operados desde ' + DTOC(M.FilDes) + ' hasta ' + DTOC(M.FilHas) + '")'
   &INSTRU
ENDIF
oHoja.getCellByPosition( 0, 4 ).setPropertyValue("CharHeight", 14)

oHoja.getCellByPosition( 0, 6 ).setString("Cuenta")
oHoja.getCellByPosition( 0, 6 ).setPropertyValue("CharHeight", 12)
oHoja.getCellByPosition( 1, 6 ).setString("Fecha")
oHoja.getCellByPosition( 1, 6 ).setPropertyValue("CharHeight", 12)
oHoja.getCellByPosition( 2, 6 ).setString("Número")
oHoja.getCellByPosition( 2, 6 ).setPropertyValue("CharHeight", 12)
oHoja.getCellByPosition( 3, 6 ).setString("Monto Q")
oHoja.getCellByPosition( 3, 6 ).setPropertyValue("CharHeight", 12)
oHoja.getCellByPosition( 4, 6 ).setString("Emitido A")
oHoja.getCellByPosition( 4, 6 ).setPropertyValue("CharHeight", 12)

oColumnas = oHoja.getColumns()
oCol_A = oColumnas.getByName("A")
oCol_A.Width = 12000
oColumnas = oHoja.getColumns()
oCol_B = oColumnas.getByName("B")
oCol_B.Width = 2400
oColumnas = oHoja.getColumns()
oCol_C = oColumnas.getByName("C")
oCol_C.Width = 4100
oColumnas = oHoja.getColumns()
oCol_D = oColumnas.getByName("D")
oCol_D.Width = 3900
oColumnas = oHoja.getColumns()
oCol_E = oColumnas.getByName("E")
oCol_E.Width = 32000

M.NumRec = 0
M.NumFil = 7
SCAN REST
   M.INSTRU = 'oHoja.getCellByPosition(0, ' + ALLTRIM(STR(M.NumFil)) + ').setString("' + IIF(SEEK(MovBancos.CodCbn, 'Chequeras'), MovBancos.CodCbn + ' / ' + ALLTRIM(Chequeras.NumCbn) + '-' + Chequeras.NomCbn, MovBancos.CodCbn) + '")'
   &INSTRU
   M.INSTRU = 'oHoja.getCellByPosition(1, ' + ALLTRIM(STR(M.NumFil)) + ').setString("' + DTOC(MovBancos.FecDoc) + '")'
   &INSTRU
   M.INSTRU = 'oHoja.getCellByPosition(2, ' + ALLTRIM(STR(M.NumFil)) + ').setString("' + (MovBancos.NumDoc + IIF(EMPTY(MovBancos.FecCon), '', '-CON')) + '")'
   &INSTRU
   IF EMPTY(MovBancos.FecAnu)
      M.INSTRU = 'oHoja.getCellByPosition(3, ' + ALLTRIM(STR(M.NumFil)) + ').setValue(' + ALLTRIM(TRANSFORM(MovBancos.TotDeb + MovBancos.TotHab, "999999999.99")) + ')'
   ELSE
      M.INSTRU = 'oHoja.getCellByPosition(3, ' + ALLTRIM(STR(M.NumFil)) + ').setString("ANULADO")'
   ENDIF
   &INSTRU
   M.INSTRU = 'oHoja.getCellByPosition(4, ' + ALLTRIM(STR(M.NumFil)) + ').setString("' + ALLTRIM(MovBancos.NomChe) + ' / ' + ALLTRIM(ALLTRIM(MovBancos.DetLn1) + ' ' + ALLTRIM(MovBancos.DetLn2) + ' ' + ALLTRIM(MovBancos.DetLn3)) + '")'
   &INSTRU
   M.NumFil = M.NumFil + 1
   M.NumRec = M.NumRec + 1
ENDSCAN

oHoja.GetCellByPosition(2, M.NumFil).SetString("        Total Q")
M.INSTRU = 'oHoja.getCellByPosition(3, M.NumFil).SETFormula("=SUM(D8:D' + ALLTRIM(STR(M.NumFil)) + ')")'
&INSTRU
M.INSTRU = 'oHoja.GetCellByPosition(4, M.NumFil).SetString("   Un total de ' + ALLTRIM(TRANSFORM(M.NumRec, "999,999")) + ' Cheques en este listado.")'
&INSTRU

M.NumFil = M.NumFil + 1

oFormat = oDoc.NumberFormats
M.INSTRU = 'oHoja.getCellRangeByName("D8:D' + ALLTRIM(STR(M.NumFil)) + '").NumberFormat =NumberFormat(@oReflectX, oFormat, "#,###.00")'
&INSTRU

M.INSTRU = 'oHoja.getCellRangeByName("A8:F' + ALLTRIM(STR(M.NumFil)) + '").setPropertyValue("CharHeight", 8)'
&INSTRU


El 22 de julio de 2011 15:27, apzavaleta <impre...@gmail.com> escribió:
Reply all
Reply to author
Forward
0 new messages