如何在 LibreOffice 中运行 python 宏?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21413664/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to run python macros in LibreOffice?
提问by Martin Drozdik
When I go to Tools -> Macros -> Organize Macros -> PythonI get this dialog:
当我去工具 -> 宏 -> 组织宏 -> Python我得到这个对话框:


It is not possibleto create new Python macros.
这是不可能创造新的Python宏。
Apparently LibreOffice has no Python editorso I have to write the macros elsewhere and then just execute them.
显然 LibreOffice没有 Python 编辑器,所以我必须在别处编写宏,然后执行它们。
But I do not know whereto put the Python scripts.
但我不知道把 Python 脚本放在哪里。
I tried a system-wide search for files with "HeloWorld"in their name and I got no results.
我尝试在系统范围内搜索名称中带有“HeloWorld”的文件,但没有得到任何结果。
I tried to put a test.pyfile into:
我尝试将test.py文件放入:
/home/martin/.config/libreoffice/4/user/Scripts
and reload the application, but the testmacro is not shown.
并重新加载应用程序,但未显示测试宏。
I tried to find the appropriate setting in Tools -> Options -> Pathbut there is no "path to macros":
我试图在工具 -> 选项 -> 路径中找到适当的设置,但没有“宏路径”:


How can I run Python macros from LibreOffice?
如何从 LibreOffice 运行 Python 宏?
This question is a part of my quest to learn Python and to learn LibreOffice macros, so any link to a general tutorial is welcomed. The tutorials on LibreOffice Python macrosseem to be especially hard to find.
这个问题是我学习 Python 和学习 LibreOffice 宏的探索的一部分,因此欢迎任何指向一般教程的链接。关于LibreOffice Python 宏的教程似乎特别难找。
I am using LibreOffice Version: 4.1.3.2
我使用的是LibreOffice 版本:4.1.3.2
采纳答案by halex
Try to manually make a subdirectory python(all lowercase) inside /home/martin/.config/libreoffice/4/user/Scriptsand put your script there.
尝试在里面手动创建一个子目录python(全部小写)/home/martin/.config/libreoffice/4/user/Scripts并将您的脚本放在那里。
This is based on this wiki.openoffice.org documentations.
回答by Jannie Theunissen
I also struggled to get a clear start, so I documented my setup and the things I learned here. If you work through that, you will see that you can place your python script in any folder as long as you link to it correctly.
我也很难有一个清晰的开始,所以我记录了我的设置和我在这里学到的东西。如果你解决了这个问题,你会发现你可以将你的 python 脚本放在任何文件夹中,只要你正确链接到它。
EDIT:The old URL-only answer now points to a dead link. That page can still be found on the Internet Archive Wayback Machineor this GitHub Gist.
编辑:旧的 URL-only 答案现在指向一个死链接。该页面仍然可以在Internet Archive Wayback Machine或此 GitHub Gist 上找到。
回答by Γι?ννη? Πετρ?ρχη?
Python scripts are located on /usr/lib/libreoffice/share/scripts/python
Python 脚本位于 /usr/lib/libreoffice/share/scripts/python
Maybe this tutorialwill help, as it did for me.
也许本教程会有所帮助,就像对我一样。
回答by Jim K
Follow these instructions:
请按照以下说明操作:
- Install the new APSO extension
- then go to Tools -> Macros -> Organize python scripts.
- Now, select "My Macros" and choose Menu -> Create Module.
- 安装新的APSO 扩展
- 然后转到工具 -> 宏 -> 组织 python 脚本。
- 现在,选择“我的宏”并选择“菜单”->“创建模块”。
This documentationhelped me the most.
该文档对我帮助最大。

