Skip to content
hanya edited this page Dec 21, 2011 · 4 revisions

OpenOffice.org supports named-pipe connection and TCP/IP connection, so called RPC.

  1. The office have to be started with accept option which specifies connection type or other connection environment.
  2. The script of Ruby which want to connect to the office started with the accept option, have to be connect with the same environment.

For example, the office is starting with the following option:
soffice "-accept=socket,host=localhost,port=2083;urp;StarOffice.ServiceManager"
In this case, the instance of OpenOffice.org allows to connect from localhost and listening at port 2083.

There is a helper functions to connect to the office which allows to connect through RPC.
Use Uno::Connector.

requre 'uno'

office = "/opt/openoffice.org3/program/soffice"
ctx = Uno::Connector.bootstrap(office)
smgr = ctx.getServiceManager
desktop = smgr.createInstanceWithContext(
                 "com.sun.star.frame.Desktop", ctx)
doc = desktop.loadComponentFromURL("private:factory/swriter", "_blank", 0, [])
doc.getText.setString("Hello Ruby!")

See rpc.rd for more detail.

Reference

Try to connect according to the following section of OpenOffice.org Developer’s Guide:
http://wiki.services.openoffice.org/wiki/Documentation/DevGuide/ProUNO/UNO_Interprocess_Connections

The following section is little bit old.


Try to connect according to the following section of OpenOffice.org Developer’s Guide:
http://wiki.services.openoffice.org/wiki/Documentation/DevGuide/ProUNO/UNO_Interprocess_Connections

Start OpenOffice.org with -accept option. For example:
soffice "-accept=socket,host=localhost,port=2083;urp;StarOffice.ServiceManager"
In this case, the instance of OpenOffice.org allows to connect from localhost and listening at port 2083.

# coding: utf-8
require 'runo'

def connect
  local_ctx = Runo.get_component_context
  local_smgr = local_ctx.getServiceManager
  resolver = local_smgr.createInstanceWithContext(
      'com.sun.star.bridge.UnoUrlResolver', local_ctx)
  resolver.resolve('uno:socket,host=localhost,port=2083;urp;StarOffice.ComponentContext')
end

ctx = connect
if ctx.nil?
  print 'failed to connect.'
  exit
end

smgr = ctx.getServiceManager
desktop = smgr.createInstanceWithContext('com.sun.star.frame.Desktop', ctx)
doc = desktop.loadComponentFromURL('private:factory/swriter', '_blank', 0, [])
doc.getText.setString('Honyo honyo.')
Clone this wiki locally