Clase tWord y LibreOffice

Clase tWord y LibreOffice

Postby gsabattino » Sat Jun 05, 2021 10:54 pm

Mis estimados del Foro... Buen Saludos y Dia a todos...

he usado por mucho tiempo, y de manera muy satisfactoria, la clase tWord y la caracteristica de combinación de correspondencia del Office de MicroSoft...
el asunto esta ahora que personalmente me cambie a Libre Office, y de hecho he ido animando a mis clientes a migrar a dicha aplicación, pero ahora se me presenta el pequeño problema que la clase tWord no funciona con Libre Office... alguien ya ha tenido alguna experiencia respecto a ese tema??? o hay alguna clase al estilo tWord que pueda utilizar con Libre Office???

Gracias de antemano a todos por sus comentarios...

Giancarlo Sabattino
Valencia, Venezuela
User avatar
gsabattino
 
Posts: 102
Joined: Fri Oct 14, 2005 12:03 am
Location: Valencia, Venezuela

Re: Clase tWord y LibreOffice

Postby karinha » Sun Jun 06, 2021 11:24 pm

Mira se ayuda:

Code: Select all  Expand view  RUN

#Include "FGet.ch"  

Function LIBRE_OFFICE()

   Local oService, oDesktop, oDocument, oTexto
   Local oDlg, oGet, cVarTxt, cFile, aProp:={}

   cFile := cGetFile( "Arquivo (doc,odt)|*.doc;*.odt|",;
                      "Selecione o Arquivo (Doc/Odt)", 4 )

   IF EMPTY(cFILE) ; RETURN nil ; ENDIF

      cFile := "file:///"+StrTran(cFile,"\","/")

   TRY

      oService := TOleAuto():New("
com.sun.star.ServiceManager")

   CATCH

      MsgStop( "
Desculpe, precisa ter o LiBreOffice instalado.", "Alerta" )

      RETURN NIL

   END

   oDesktop := oService:createInstance("
com.sun.star.frame.Desktop")

   AAdd(aProp,MakePropertyValue(oService,"
Hidden",.T.)) //seta prop para ocultar

   oDocument := oDesktop:loadComponentFromURL(cFile, "
_blank", 0, aProp) // {}) //abre o doc

   //OBTÉM O TEXTO

   oTexto = oDocument:getText()

   cVarTxt := oTexto:getString()

   oDocument:Close(.T.) //fechao doumento

   DEFINE DIALOG oDlg TITLE "
Visualiza documentos doc/odt" SIZE 640,480

   oDlg:lHelpIcon := .F.

   @ 0.5, 01 FORMAT GET oGet VAR cVarTXT OF oDlg SIZE 310,220 UPDATE

   ACTIVATE DIALOG oDlg CENTERED

Return Nil
**============================================================================
STATIC FUNCTION MakePropertyValue( oService, cName, nValue )

   LOCAL oStruct := oService:Bridge_GetStruct("
com.sun.star.beans.PropertyValue")

   oStruct:Name := cName

   oStruct:Value := nValue

RETURN(oStruct)


Saludos.
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
User avatar
karinha
 
Posts: 7843
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: Clase tWord y LibreOffice

Postby gsabattino » Mon Jun 07, 2021 11:03 am

João, Agradecido por la ayuda... voy a probarlo y cualquier cosa te estare comentando.
User avatar
gsabattino
 
Posts: 102
Joined: Fri Oct 14, 2005 12:03 am
Location: Valencia, Venezuela

Re: Clase tWord y LibreOffice

Postby karinha » Mon Jun 07, 2021 12:57 pm

+ ejemplos:

Code: Select all  Expand view  RUN

// http://fivewin.com.br/index.php?/topic/ ... mment-1278

Olá

Uso o brOffice desta forma, abro ".DOC" ou ".ODT" e exibo o texto em um Dialog.

Veja o exemplo:

/*

** autor: JOSÉ MARIA DA SILVA (JMSILVA)

** xHarbour 1.2.1 com FIVEWIN

** DATA: 29/12/2011

** CIDADE: CARAGUATATUBA/SP

** OBS: PRECISA TER BROFFICE INSTALADO

*/


#INCLUDE "FIVEWIN.CH"

#include "FGet.ch"

Function Main ()

Local oService,oDesktop,oDocument,oTexto

Local oDlg,oGet,cVarTxt,cFile,aProp:={}

cFile := cGetFile("Arquivo (doc,odt)|*.doc;*.odt|",;

"Selecione o Arquivo (Doc/Odt)", 4 )

IF EMPTY(cFILE) ; RETURN nil ; ENDIF

cFile := "file:///"+StrTran(cFile,"\","/")

TRY

oService := TOleAuto():New("
com.sun.star.ServiceManager")

CATCH

MSGSTOP("
Desculpe, precisa ter o BrOffice instalado.","Alerta")

RETURN NIL

END

oDesktop := oService:createInstance("
com.sun.star.frame.Desktop")

AAdd(aProp,MakePropertyValue(oService,"
Hidden",.T.)) //seta prop para ocultar

oDocument := oDesktop:loadComponentFromURL(cFile, "
_blank", 0, aProp) // {}) //abre o doc

//OBTÉM O TEXTO

oTexto = oDocument:getText()

cVarTxt := oTexto:getString()

oDocument:Close(.T.) //fechao doumento

DEFINE DIALOG oDlg TITLE "
Visualiza documentos doc/odt" size 640,480

@ 0.5, 01 FORMAT GET oGet VAR cVarTXT OF oDlg SIZE 310,220 UPDATE

ACTIVATE DIALOG oDlg CENTERED

Return Nil

**==============================================================================

STATIC FUNCTION MakePropertyValue(oService,cName,nValue)

**==============================================================================

LOCAL oStruct := oService:Bridge_GetStruct("
com.sun.star.beans.PropertyValue")

oStruct:Name := cName

oStruct:Value := nValue

RETURN(oStruct)

//

/*

** autor: JOSÉ MARIA DA SILVA (JMSILVA)

** xHarbour 1.2.1 com FIVEWIN

** DATA: 29/12/2011

** CIDADE: CARAGUATATUBA/SP

** OBS: PRECISA TER BROFFICE INSTALADO

** “writer_pdf_Export†=> Para salvar arquivos do Writer como PDF

*/

#INCLUDE "
FIVEWIN.CH"

Function Main ()

Local oService,oDesktop,oDocument,oZip,oTip,oBRUSH,oActiveX

Local oDlg,oGet,cFile,aProp:={},cFilePDF,cSUrl

cFile := cGetFile("
Arquivo (doc,odt)|*.doc;*.odt|",;

"
Selecione o Arquivo (Doc/Odt)", 4 )

IF EMPTY(cFILE) ; RETURN nil ; ENDIF

cFile := "
file:///"+StrTran(cFile,"\","/")

TRY

oService := TOleAuto():New("com.sun.star.ServiceManager")

CATCH

MSGSTOP("Desculpe, precisa ter o BrOffice instalado.","Alerta")

RETURN NIL

END

oDesktop := oService:createInstance("com.sun.star.frame.Desktop")

AAdd(aProp,MakePropertyValue(oService,"Hidden",.T.)) //seta prop para ocultar

oDocument := oDesktop:loadComponentFromURL(cFile, "_blank", 0, aProp) // {}) //abre o doc

//exportar para pdf

cFilePDF := "e:\xhbtest\test_PDF.pdf"

cSUrl := "file:///"+StrTran(cFilePDF,"\","/")

oZip := MakePropertyValue(oService, "
CompressMode", 1)

oTip := MakePropertyValue(oService, "
FilterName", "writer_pdf_Export")

oDocument:storeToURL(cSUrl, {oZip,oTip})

oDocument:Close(.T.) //fechao doumento

DEFINE BRUSH oBrush STYLE "
BORLAND"

DEFINE DIALOG oDlg TITLE "
Visualiza documentos doc/odt" size 640,480;

BRUSH oBrush

oActiveX := TActiveX():New(oDlg,"
AcroPDF.PDF.1",3,2,;

oDlg:nRight/2-5,oDlg:nBottom/2-5)

ACTIVATE DIALOG oDlg CENTERED;

ON INIT (oActiveX:Do("
LoadFile",cFilePDF), oActiveX:Do("SetCurrentPage",1))

oDlg:End()

//apaga pdf

//Ferase(cFilePDF)

Return Nil

**==============================================================================

STATIC FUNCTION MakePropertyValue(oService,cName,nValue)

**==============================================================================

LOCAL oStruct := oService:Bridge_GetStruct("
com.sun.star.beans.PropertyValue")

oStruct:Name := cName

oStruct:Value := nValue

RETURN(oStruct)

//

// WORD

#Include "
Fivewin.ch"

**==============================================================================

Function Main()

**==============================================================================

LOCAL cFile := CurDrive()+"
:\"+CurDir()+"\teste.doc"

LOCAL oWord, oDocument, oText, cText

TRY

oWord := CreateObject( "
Word.Application" )

CATCH

MsgStop("
ERRO! Word não instalado.","Alerta")

RETURN Nil

END

oDocument := oWord:documents:open(cFile) //abre um arquivo doc/rtf

// get -> seleciona o objeto

oText := oWord:selection()

// oculta o word

oWord:visible := .F.

cText := oText:Text

oDocument:close() //fecha o doc

oWord:quit() //finaliza

MsgInfo(cText)

Return Nil

#Include "
Fivewin.ch"

**==============================================================================

Function Main()

**==============================================================================

LOCAL cFile := CurDrive()+"
:\"+CurDir()+"\teste.doc"

LOCAL oWord, oDocument, oText, cText

TRY

oWord := CreateObject( "
Word.Application" )

CATCH

MsgStop("
ERRO! Word não instalado.","Alerta")

RETURN Nil

END

// oculta o word

oWord:visible := .F.

//--

oDocument := oWord:documents:open(cFile) //abre um arquivo doc/rtf

//--

oDocument:Activate() //novo

//--

oRng := oDocument:Content //novo

oRng:Select() //novo

//--

oText := oWord:selection()

cText := oText:Text

//--

oDocument:close() //fecha o doc

oWord:quit() //finaliza

//--

MsgStop(cText)


Saludos.
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
User avatar
karinha
 
Posts: 7843
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil


Return to FiveWin para Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 85 guests