Top > OOoSF > Jython > Automation

* オートメーション [#gbde42eb]

Java と同じように接続する。

#code(python){{
import sys
sys.path.append("/home/user/opt/ooo-dev/basis3.2/program/classes/unoil.jar")
sys.path.append("/home/user/opt/ooo-dev/ure/share/java/juh.jar")
sys.path.append("/home/user/opt/ooo-dev/ure/share/java/jurt.jar")
sys.path.append("/home/user/opt/ooo-dev/ure/share/java/ridl.jar")


from com.sun.star.comp.helper import Bootstrap
from com.sun.star.uno import UnoRuntime
from com.sun.star.bridge import XUnoUrlResolver


def jython_connect():
    ctx = None
    try:
        localctx = Bootstrap.createInitialComponentContext(None)
        resolver = localctx.getServiceManager().createInstanceWithContext("com.sun.star.bridge.UnoUrlResolver", localctx)
        xResolver = UnoRuntime.queryInterface(XUnoUrlResolver, resolver)
        ctx = xResolver.resolve("uno:socket,host=localhost,port=2002;urp;StarOffice.ComponentContext")
        #uno:pipe,name=javapipe;urp;StarOffice.ComponentContext")
    except Exception, e:
        print("Error: " + str(e))
    return ctx


if __name__ == "__main__":
    ctx = jython_connect()
    if ctx:
        print("connected.")

sys.exit(0)
}}

soffice が見つかる配置なら Bootstrap.bootstrap()。

Reload   New Lower page making Edit Freeze Diff Upload Copy Rename   Front page List of pages Search Recent changes Backup   Help   RSS of recent changes