OO-Snippets: Connect to Open Office

Commons

Keywordsconnect, acceptor, other, different, macro, program
LanguageooRexx
ApplicationOffice
AuthorsJosef Frysak (initial)
Supported Versions2.4.1  
Supported OSAll  
QuestionHow to connect to Open Office from another Program?
Answer

First describe the UNO-URL, which describes where the acceptor is located.

Then create a bootsrap object and with this bootstrap object create a

component context object. Next get the Servicemanager of the component

context, which is an interface, and use it to create a connection service

(UnoUrlResolver). Finally tell the connection service to connect to the

previously prepared UNO-URL.

For further details see http://wi.wu-wien.ac.at/rgf/diplomarbeiten/BakkStuff/2008/200809_Frysak/200809_Frysak_Automating_OOo_ooRexx_Nutshells.pdf.

Code-Snippet-Listing (snippet-source)

-- identify target program
unourl = "uno:socket,host=localhost,port=2002;urp;StarOffice.ServiceManager"
-- create bootstrap object
bootstrap = uno.wrap(.bsf~new("com.sun.star.comp.helper.Bootstrap"))
-- create the Component Context
x_ComponentContext = bootstrap~createInitialComponentContext(.nil)
-- get the UNO Service Manager
s_UnoServiceManager = x_ComponentContext~getServiceManager()
-- create an UNO connection interface
urlresolver = "com.sun.star.bridge.UnoUrlResolver"
s_UnoUrlResolver = s_UnoServiceManager~createInstanceWithContext(urlresolver, x_ComponentContext)
x_UnoUrlResolver = s_UnoUrlResolver~XUnoUrlResolver
-- connect to Open Office and retrieve "StarOffice.ServiceManager" service
s_ServiceManager = x_UnoUrlResolver~resolve(unourl)
::requires UNO.CLS

Changelog

DateUserModification
2008-10-121Initial version

and