python openoffice_我有 Python 连接 openoffice 后,日志里发现 python 连接 openoffice socket 很费时间...

这么写一个helloworld就贼慢,以后在做pdf,doc等转矢量图那就更慢了,请问有啥办法么?

日志:

2015-08-03 18:30:56,804 [CALL,tid 1]: Instantiating pyuno bridge

2015-08-03 18:30:56,808 [CALL,tid 1]: try py->uno[0x7fd8e9b51c30].createInstanceWithContext((string)"com.sun.star.bridge.UnoUrlResolver", (com.sun.star.uno.XComponentContext)0x7fd8e9bdcd18)

2015-08-03 18:30:56,809 [CALL,tid 1]: success py->uno[0x7fd8e9b51c30].createInstanceWithContext()=(com.sun.star.uno.XInterface)0x7fd8e9baf288

2015-08-03 18:30:56,809 [CALL,tid 1]: try py->uno[0x7fd8e9b51e30].resolve((string)"uno:socket,host=localhost,port=2002;urp;StarOffice.ComponentContext")

#此处等待30s以上

2015-08-03 18:31:56,892 [CALL,tid 1]: success py->uno[0x7fd8e9b51e30].resolve()=(com.sun.star.uno.XInterface)0x167e7d8

2015-08-03 18:31:56,907 [CALL,tid 1]: try py->uno[0x7fd8e9b51d30].createInstanceWithContext((string)"com.sun.star.frame.Desktop", (com.sun.star.uno.XInterface)0x167e7d8)

2015-08-03 18:31:56,908 [CALL,tid 1]: success py->uno[0x7fd8e9b51d30].createInstanceWithContext()=(com.sun.star.uno.XInterface)0x1687a88

2015-08-03 18:31:56,928 [CALL,tid 1]: try py->uno[0x7fd8e9b9a038].getCurrentComponent()

2015-08-03 18:31:56,929 [CALL,tid 1]: success py->uno[0x7fd8e9b9a038].getCurrentComponent()=(com.sun.star.lang.XComponent)0x1696828

2015-08-03 18:31:56,983 [CALL,tid 1]: try py->uno[0x7fd8e16f6060].createTextCursor()

2015-08-03 18:31:56,984 [CALL,tid 1]: success py->uno[0x7fd8e16f6060].createTextCursor()=(com.sun.star.text.XTextCursor)0x16d79d8

2015-08-03 18:31:57,000 [CALL,tid 1]: try py->uno[0x7fd8e16f6060].insertString((com.sun.star.text.XTextCursor)0x16d79d8, (string)"Hello World", (byte)0x0)

2015-08-03 18:31:57,002 [CALL,tid 1]: success py->uno[0x7fd8e16f6060].insertString()=void

python程序:

import socket

import uno

#get the uno component from the PyUNO runtime

localContext = uno.getComponentContext()

#create the UnoUrlResolver

resolver = localContext.ServiceManager.createInstanceWithContext("com.sun.star.bridge.UnoUrlResolver",localContext)

#connect to the running office

ctx = resolver.resolve("uno:socket,host=localhost,port=2002;urp;StarOffice.ComponentContext")

smgr = ctx.ServiceManager

# get the contral desktop object

desktop = smgr.createInstanceWithContext("com.sun.star.frame.Desktop",ctx)

# access the current writer document

model = desktop.getCurrentComponent()

# access the document's text property

text = model.Text

# create a cursor

cursor = text.createTextCursor()

# Insert the text into the document

text.insertString(cursor,"Hello World",0)

# Do a nasty thing before exiting the python process. In case the

# last call is a oneway call (e.g. see idl-spec of insertString),

# it must be forced out of the remote-bridge caches before python

# exits the process. Otherwise, the oneway call may or may not reach

# the target object.

# I do this here by calling a cheap synchronous call (getPropertyValue).

ctx.ServiceManager

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值