LibreOffice Calc & Python Programming: Part 1 – Requirements

I am finally starting to write this tutorial. Thanks for your patience, and thanks to Nukool for your comment, it really gave me motivation to write this course.

In this Part 1 of LibreOffice Calc & Python programming tutorial we are looking at:

Software

LibreOffice

You will of course need LibreOffice, you can download the latest version here.
LibreOffice is normally shipped with a PyUNO bridge to bind its components with Python language and to make it possible to program LibreOffice with Python. (see at end of this article if you’re using a Linux ).

Python 3

You also need the Python 3 programming language on your computer.
It may be installed already. For now I let you do it yourself, but I might write a quick help later. Just web search for ‘python 3’ for your Operating system.

IDE / Text Editor

You will also need a text editor or even better an IDE (Integrated Development Environment) to write your python program. The advantage of an IDE versus a simple text editor is that it offers tools to organise your codes, an IDE can also makes it easier to spot errors and offers all sort of features to speed up and ease coding like word auto-completion, search and replace.
If you are a programmer you may already have a preference for a simple editor or a clever one. I am using a free open-source IDE called geany, but other popular ones are Eclipse, code::block and the famous Microsoft Visual Studio. They all have their pros and cons, here is the Top 20 of the most popular ones. Geany is perfect for ‘small jobs’ like we are going to do, but again it’s also fine to use a text editor like notepad.

JRE install

If your computer does not have Java Runtime Environment already you will need to install it through the Oracle website. You can also follow instruction here. JRE is indeed required to be able to use macros within LibreOffice.

APSO extension

By default LibreOffice Python Macros are independent from any LibreOffice file. So to execute a python program within a LibreOffice Calc Spreadsheet for example you would need to go in Tools/Macro/Run Macro and select the python program from a list corresponding to a folder on your Hard drive. And this list, for example ‘MyMacro’, would be accessible for any LibreOffice file (Calc, Text, Base, etc…). This is great but not helpful when you want a particular python program to be used specifically for a particular file.
APSO is a LibreOffice extension that helps with organising Python Macros within your LibreOffice files. You just need to download the APSO extension here and then install the tool via Tools/Extensions Manager. One great advantage of APSO is its EditorKicker that you can set up to use your preferred text editor or IDE to edit your Python program.
One last note about using APSO, although the program themselves are saved in the same folders than all other programs, the ones you choose to be embed in a particular file will be linked to that file, or rather for example LibreOffice calc file will have a link to the python program in its parameters and you will be able to see your program attached to LibreOffice documents currently opened.

Extra step for linux

I had to do one extra step when I was using LibreOffice 5 under Linux mint Operating System: adding some library. Without it it was not possible to do any Python macros within LibreOffice. This is an easy step, just open a terminal, type and execute:

sudo apt-get install libreoffice-script-provider-python

It will be the same for Ubuntu. For other linux distro you will need to check yourself but it’d be similar using the in-house package manager.

Documentation

It is not easy to find helpful documentation for programming Python Macros for LibreOffice. Firstly it’s hard to find a site or forum that have real documentation about using Python for LibreOffice, and secondly the tasks explained are usually too complicated for a beginner. However this is the best place I found so far with a list of links to Python program examples. You will not that most of the examples are using a Python library created by ‘Danny’.

Further notes

In my tutorial we will create everything from scratch and develop simple and useful functions.
I still haven’t decided what topic to cover to illustrate this tutorial. I am hesitating between continuing the time schedule, starting invoice manager or a garden planner.
If you have any preference please let me know in your comment.

5 Comments

  1. Nukool Chompuparn

    Thank you so much again.
    I use Fedora 30 Workstation KDE from Fedora Spins and LibreOffice 6.2.5.2.

    Reply
  2. Nukool Chompuparn

    I use Fedora 30 Workstation KDE from Fedora Spins and LibreOffice 6.2.5.2.
    In LibreOffice Calc, there is an messsage box showing right after I select Tools > Macros > Organize Macros > Python.
    The title caption is ‘JRE Required’.
    And the message caption is ‘LibreOffice requires a Java runtime environment (JRE) to perform this task. Please install a JRE and restart LibreOffice’.

    What could be the cause of this error ?

    Reply
    1. gweno (Post author)

      Hi Nukool. Yes Java Runtime Environment is required, I had it already installed on my Linux Mint station, and my Ubuntu one as well. Thanks for pointing it out, I will add a note in my post. It seems JRE is required for a lot of features in LibreOffice (like LibreOffice Base as well). You can download Java RE from the Oracle website.Thanks

      Reply
  3. Nukool Chompuparn

    1. The LO developer said such ‘Java Required’ is a bug and they have modified already in newer version.
    2. In apso website, it supports only LO 6.2. Now I have installed 6.3.0.4, will apso work on this LO version or should I wait for the announcement from apso website ?

    Reply
    1. gweno (Post author)

      Hi, thanks for sharing your findings about the Java bug. Regarding APSO they haven’t checked compatibility with L.O. 6.3 yet indeed, I had a look at 6.3 new features, I’d be surprised if APSO doesn’t work on it.

      Reply

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.