Top > OOoSF > Jython > Automation

オートメーション Edit

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

  0
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
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