사무실 내에서 일반 사무실과 파이썬 매크로를 실행할 수 있다는 것을 확인했지만 여전히 실행 방법을 찾지 못했습니다. 안녕하세요?) 명령 줄에서.libreoffice - Gnu/Linux 명령 줄에서 상호 참조를 삽입하기위한 (python) 매크로 실행
내가 봤 여기에 다른 답변 보았다하지만, 난 여전히 명령 줄에서 오픈 오피스 매크로를 실행하는 방법을 완전히 명확하지 않다 않은 :
https://forum.openoffice.org/en/forum/viewtopic.php?f=20&t=8232 사용 제안을 :
office writer.odt "macro://Standard.Module1.Macro1()"
또한 본 :
office "macro://Standard.Module1.Macro1()"
writer.odt
이 방법을 사용하면 문서를 열고 매크로를 실행하거나 오류를보고하지 않습니다.
반면에 How to call an existing LibreOffice python macro from a python script 은 사무실에서 포트를 수신하고이를 통해 통신하도록 제안합니다.
내가 그 얻을 수 있다면 지금까지 난 아직도 문맥 RHEL7을 사용하고
(내 다른 질문 asciidoc: is there a way to create an anchor that will be visible in libreoffice writer?에 따라) 앵커를 삽입하는 방법을 설명합니다 API 문서를 찾을 필요가있다. 사무실 기본적인 매크로
업데이트는
oowriter "foo.odt" macro:///Standard.Module1.addXref
작품. 아직 파이썬 중 하나를 알아 내지 못했습니다.
하나의 문제는 내가 볼 디버그 정보를 찾을 수 없다는 것입니다. 로그 파일이 있습니까?
다른 문제는 사용할 파이썬 버전입니다. RHEL 패키지는 python 2.7 용 사이트 패키지를 설치합니다.
>rpm -q --whatprovides /usr/bin/writer libreoffice-writer-4.3.7.2-5.el7_2.1.x86_64 >rpm -ql libreoffice-pyuno-4.3.7.2-5.el7_2.1 ... /usr/lib64/python2.7/site-packages/uno.py
Libreoffice5.1는 배포판 3.5 포함 : 나는 안녕하세요 세계 파이썬 예제를 찾고 있어요와
>/opt/libreoffice5.1/program/python --version Python 3.5.0
그래서
이 시작을 그 쌍 알려진 버전 파이썬 알려진 버전 사무실. 바람직하게는 위의 두 가지 중 하나 (작가 4.3.7 & 파이썬 2.7? 또는 작가 5.파이썬 3.5). office5 설치로 python3.5를 사용
갱신 2
.(1) 나는 다음과 같은 사용하여 작업 안녕하세요 세계를 가지고 :
/usr/bin/oowriter --accept="socket,host=localhost,port=2002;urp;StarOffice.ServiceManager"
그래서 마지막 부분은 상호 참조를 추가하는 것입니다
는import uno
# get the uno component context 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 central 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)
이를 통해 오픈 오피스의 두 버전에서 작동합니다.
oowriter "foo.odt"매크로 : ///Standard.Module1.addXref는 office 기본 매크로와 함께 작동합니다. –
(http://stackoverflow.com/questions/37611030/how-do-i-check-for-broken-internal-links-in-star-basic)에 링크 된'coool' 스크립트는 흥미롭지 만, 사용할 파이썬 버전을 나타냅니다. 2.7.5가 아닌 3.x –
'coool' 스크립트가 작동하려면, 코드를 다운로드하고,'configparse' 모든 것을 주석 처리하고, 파이썬 3 라이브러리를 사용하도록 업데이트했습니다. 약 1 시간이 걸렸다. –