29

When I go to Tools -> Macros -> Organize Macros -> Python I get this dialog:

enter image description here

It is not possible to create new Python macros.

Apparently LibreOffice has no Python editor so I have to write the macros elsewhere and then just execute them.

But I do not know where to put the Python scripts.

I tried a system-wide search for files with "HeloWorld" in their name and I got no results.

I tried to put a test.py file into:

/home/martin/.config/libreoffice/4/user/Scripts

and reload the application, but the test macro is not shown.

I tried to find the appropriate setting in Tools -> Options -> Path but there is no "path to macros":

enter image description here

How can I run Python macros from LibreOffice?

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 macros seem to be especially hard to find.

I am using LibreOffice Version: 4.1.3.2

Martin Drozdik
  • 12,742
  • 22
  • 81
  • 146
  • 3
    Try to manually make a subdirectory `python` (all lowercase) inside `/home/martin/.config/libreoffice/4/user/Scripts` and put your script there. – halex Jan 28 '14 at 18:29
  • 2
    Good to help you :) Addendum: This advice is based on https://wiki.openoffice.org/wiki/Python_as_a_macro_language – halex Jan 28 '14 at 18:41
  • Thanks, reported: https://bugs.documentfoundation.org/show_bug.cgi?id=126390 – Hi-Angel Jul 14 '19 at 20:41

5 Answers5

20

Try to manually make a subdirectory python (all lowercase) inside /home/martin/.config/libreoffice/4/user/Scripts and put your script there.

This is based on this wiki.openoffice.org documentations.

Foad S. Farimani
  • 12,396
  • 15
  • 78
  • 193
halex
  • 16,253
  • 5
  • 58
  • 67
  • 2
    Does libreoffice provide similar documentation? Is there any difference between libreoffice and openoffice? – Anthony Kong Jan 31 '15 at 23:18
  • The documentation works for LibreOffice as well. There are very few differences, similar to differences between one version of LibreOffice and another. – Jim K May 11 '18 at 12:46
5

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.

EDIT: The old URL-only answer now points to a dead link. That page can still be found on the Internet Archive Wayback Machine or this GitHub Gist.

Jannie Theunissen
  • 28,256
  • 21
  • 100
  • 127
  • This says ERR_CONNECTION_TIMED_OUT. I guess this is why "link-only" answers are [not considered as answers](https://meta.stackoverflow.com/a/265553/2388257), and I'm flagging it as such. – Hi-Angel Jul 14 '19 at 20:26
  • The OP specifically asks for "any link to a general tutorial", so in this case a proper answer can be a link, right? – Jannie Theunissen Jul 15 '19 at 06:31
  • Dear Jannie, I moved your post to this [GitHub Gist](https://gist.github.com/Foadsf/58d401c9b9ed5d80f60deee88d1fcdfd). Any chance that I can find you on Twitter? – Foad S. Farimani Mar 05 '20 at 13:04
3

Python scripts are located on /usr/lib/libreoffice/share/scripts/python

Maybe this tutorial will help, as it did for me.

Foad S. Farimani
  • 12,396
  • 15
  • 78
  • 193
1

Follow these instructions:

  1. Install the new APSO extension
  2. then go to Tools -> Macros -> Organize python scripts.
  3. Now, select "My Macros" and choose Menu -> Create Module.

This documentation helped me the most.

Foad S. Farimani
  • 12,396
  • 15
  • 78
  • 193
Jim K
  • 12,824
  • 2
  • 22
  • 51
0

for a short intro on how to run python macros in LibreOffice Calc, you may check Python Macros in LibreCalc

Arun Kumar Khattri
  • 1,519
  • 15
  • 25