我一直在寻找答案,但到目前为止没有任何帮助。我有一个方法,我想用它来创建一个odt文件并用文本填充它。我还希望用户在创建文件时查看它。我使用的是python3.4.3.0.3.3 LinuxMint 17.1 LibreOffice 4.2.8.2
问题是:
unotools.errors.ConnectionError: failed to connect: ('socket,host=localhost,port=8100', {})
unotools示例在terminal中运行良好-创建并保存了示例.odt没有错误。我的草案代码:
def writer_report(self):
subprocess.Popen(["soffice", "--accept='socket,host=localhost,port=8100;urp;StarOffice.Service'"])
time.sleep(5) # using this to give time for LibreOffice to open - temporary
context = connect(Socket('localhost', '8100'))
writer = Writer(context)
writer.set_string_to_end('world\n')
writer.set_string_to_start('hello\n')
writer.store_to_url('output.odt','FilterName','writer8')
writer.close(True)
LibreOffice应用程序将打开并保持打开状态。但是,连接似乎丢失了。
希望有人能给我帮助,谢谢。你知道吗
我不推荐这样的代码:
最好使用shell脚本启动
soffice
,然后调用python脚本。你知道吗但是,如果您决定在子进程中运行
soffice
,那么我建议将睡眠时间至少增加到15秒。你知道吗见https://forum.openoffice.org/en/forum/viewtopic.php?t=1014。你知道吗
谢谢你的建议。我确实想让它运行一个子进程。我试着延长时间,但仍然没有什么乐趣。
我现在正在考虑使用Python odfpy 1.3.3包,在开始使用一两天之后,我已经获得了更多的成功。你知道吗
相关问题 更多 >
编程相关推荐