Getting started writing Python macros and UDFs

Can anyone point a new user of Libreoffice (v6.2.4.2) to a tutorial on using Python in conjunction with Calc? I would like to be able to write macros and UDFs in Python. I started with this tutorial http://christopher5106.github.io/office/2015/12/06/openoffice-libreoffice-automate-your-office-tasks-with-python-macros.html but it must be for an earlier distribution as it refers to an included python interpreter.

This is a questions-and-answers site for LibreOffice users. Yours is about development and you will probably get much quicker answers if you ask at #libreoffice-dev at FreeNode or here.

@gabix

I would simply consider this as nothing more than dealing with macros. I consider development more in line with LO core and SDK. Many questions on this site have already dealt with this.

Hello,

The link you noted worked last time I tried it. It is for interactive use. Can also do this with some IDE’s if set up correctly.

But for your question, see:

https://wiki.documentfoundation.org/Macros/Python_Design_Guide

and

https://wiki.documentfoundation.org/Macros/Python_Basics

and

https://help.libreoffice.org/6.3/en-US/text/sbasic/python/python_programming.html

for starters. You can also search this site using keyword Python and find a number of posts and examples.

@ihf Please note Python is included in LO releases through current. If you are having an issue with something please be specific.

Personally preferred to use PyCharm when dealing interactively. I set this up based upon information provided in links in answer.

That link refers to using the python interpreter found in the LibreOffice.app directory though there does not appear to be a python instance there. I will check out the links you provided though with a quick perusal I did not see an example of a UDF or a Calc macro written in Python.

@ihf

It appears you may not be looking in the correct place for Python in LO. You have not specified your OS but on my Linux Ubuntu 18.04 using LO v6.2.0.3 here it is (from terminal):

$ /opt/libreoffice6.2/program/python
Python 3.5.5 (default, Jan 24 2019, 09:05:38) 
[GCC 7.3.1 20180303 (Red Hat 7.3.1-5)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 

This is what I would use in the link you provided. Again I prefer to use PyCharm for interactive use. You can also write Python macros simply using a text editor but then no interaction.

As for a specific step-by-step, the link you have is probably the most complete.

This has more which may interest you → LibreOfficeDev Python script help

You also asked for sample code and stated in answer search in this forum. Here are just a couple of Calc macros: