Hi, I need some code to work with writer in my app. With CALC work so fine with 
this code:
(This is a class for Xharbour Languaje and y need make somethis like this, but 
for writer. Where can I look?)
Thanks
/*____________________________*/
CLASS TOpenOffice
   CLASSDATA oService
   CLASSDATA oDesktop
   CLASSDATA oDisp
   DATA oDoc
   DATA lOpen   Init .T.
   METHOD Calc( cFile )
   METHOD Close()             INLINE ::oDoc:Close( .T. )
   METHOD Copy()              INLINE ::Dispatch( "Copy" )
   METHOD ConvertToURL( cFile )
   METHOD Dispatch( cMethod, aArgs )
   METHOD GetPropertyValue( cName, cValue )
   METHOD New() Constructor
   METHOD Print()             INLINE ::Dispatch( "Print" )
   METHOD PrintDefault()      INLINE ::Dispatch( "PrintDefault" )
   METHOD Visible( lVisible )
   METHOD Paste()             INLINE ::Dispatch( "Paste" )
   METHOD Preview()           INLINE ::Dispatch( "PrintPreview" )
   ERROR HANDLER ERROR( xVal )
ENDCLASS

/*-----------------------------------------------------------------------------------------------*/
METHOD Visible( lVisible )
   IF lVisible == NIL
      RETURN 
::oDoc:getCurrentController():GetFrame():getComponentWindow():IsVisible()
   ELSE
      ::oDoc:getCurrentController():GetFrame():getComponentWindow():setVisible( 
lVisible )
   ENDIF
   RETURN NIL

/*-----------------------------------------------------------------------------------------------*/
METHOD Calc( cFile, lVisible ) CLASS TOpenOffice
   LOCAL cUrl, oSheet, aArg := {}
   ::New()
   IF !::lOpen; RETURN NIL; ENDIF
   DEFAULT lVisible := .T.
   IF cFile == NIL
      cUrl  := "private:factory/scalc"
   ELSE
      cUrl  := "file:///" + cFile
   ENDIF
   oSheet := TOOSheet()

   IF !lVisible
      AAdd( aArg, ::GetPropertyValue( "Hidden", .T. ) )
   ENDIF

   oSheet:oDoc := ::oDesktop:LoadComponentFromUrl( cUrl, "_blank", 0, aArg )
   IF ValType( oSheet:oDoc ) == "O"
      oSheet:Init()
   ELSE
      oSheet:lOpen := .F.
      MsgStop( "No se pudo iniciar el objeto" )
   ENDIF
   RETURN oSheet

/*-----------------------------------------------------------------------------------------------*/
METHOD Dispatch( cMethod, aArgs ) CLASS TOpenOffice
   DEFAULT aArgs := {}
   IF ValType( aArgs ) == "O"; aArgs := { aArgs }; ENDIF
   ::oDisp:ExecuteDispatch( ::oDoc:GetCurrentController():GetFrame(), ".uno:" + 
cMethod, "", 0, aArgs )
   RETURN NIL

/*-----------------------------------------------------------------------------------------------*/
METHOD GetPropertyValue( cName, xValue ) CLASS TOpenOffice
   LOCAL oArg
   oArg := ::oService:Bridge_GetStruct( "com.sun.star.beans.PropertyValue" )
   oArg:Name  := cName
   oArg:Value := xValue
   RETURN oArg

/*-----------------------------------------------------------------------------------------------*/
METHOD New() CLASS TOpenOffice
   IF ::oDesktop != NIL; RETURN NIL; ENDIF
   ::lOpen := .T.
   TRY
      ::oService := TOleAuto():New( "com.sun.star.ServiceManager" )
   CATCH
      MsgStop( "No se puede iniciar el servicio manager" )
      ::lOpen := .F.
   END
   IF ::lOpen
      ::oDesktop := ::oService:CreateInstance( "com.sun.star.frame.Desktop" )
      ::oDisp := ::oService:CreateInstance( "com.sun.star.frame.DispatchHelper" 
)
   ENDIF
   RETURN SELF

/*-----------------------------------------------------------------------------------------------*/
METHOD ERROR( xVal ) CLASS TOpenOffice
   MsgInfo( __GetMessage() + " Inexistente" )
   RETURN NIL

/*-----------------------------------------------------------------------------------------------*/
METHOD ConvertToURL( cFile ) CLASS TOpenOffice
   LOCAL nFor, nLen := Len( cFile )
   FOR nFor := 1 TO nLen
      IF cFile[ nFor ] == "\"
         cFile[ nFor ] := "/"
      ENDIF
   NEXT
   RETURN cFile

Reply via email to