此问题专注于Windows + LibreOffice + Python 3。
我还安装了LibreOffice(6.3.4.2),pip install unoconv
和pip install unotools
(pip install uno
是另一个不相关的库),但是在import uno
之后仍然出现此错误:
ModuleNotFoundError:没有名为“ uno”的模块
更一般地说,作为使用UNO的示例,如何使用LibreOffice UNO打开.docx文档并将其导出为PDF?]] >> 几天以来,我对此进行了广泛的搜索,但是我没有找到可重现的示例代码在Windows上运行:
无头使用soffice.exe
,请参阅我的问题+答案Headless LibreOffice very slow to export to PDF on Windows (6 times slow than on Linux)和答案上的注释:它可以与soffice.exe --headless ...
“配合使用”,但更接近COM交互(组件对象模型)的操作对于许多应用程序,因此此问题在这里
相关forum post和LibreOffice: Programming with Python Scripts,但未详细说明应在Windows上使用Python安装uno的方式;也Detailed tutorial regarding LibreOffice to Python macro writing, especially for Calc
我也尝试过这个(失败):Getting python to import uno / pyuno:
import os
os.environ["URE_BOOTSTRAP"] = r"vnd.sun.star.pathname:C:\Program Files\LibreOffice\program\fundamental.ini"
os.environ["PATH"] += r";C:\Program Files\LibreOffice\program"
import uno
此问题主要针对Windows + LibreOffice + Python3。我已经安装了LibreOffice(6.3.4.2),还安装了pip install unoconv和pip install unotools(pip install uno是另一个不相关的库,...
为了与LibreOffice进行交互,请启动在套接字上侦听的实例。我使用的COM并不多,但是我认为这相当于您所要求的COM交互。这可以在命令行上或使用Shell脚本最轻松地完成,但是它也可以使用带有时间延迟和子进程的系统调用来工作。
chdir "%ProgramFiles%\LibreOffice\program\"
start soffice -accept=socket,host=localhost,port=2002;urp;