Detailed tutorial regarding LibreOffice to Python macro writing, especially for Calc

I’ve google a bit I came empty. A lot of bits and pieces but nothing detailed and to the point that explains everything from setup to the API and to the why. Most of it expect intimate knowledge of LibreOffice API.

I am not a programmer, I only dabble in this. Are there any resources out there that are not for helping people that don’t need help?

1 Like

You sure it must be Python? Ok, We may be near to the crest of the Python wave. We had a Java wave, too, which may have reach the beach meanwhile. Now and then there will be a version upgrade of Python. It seems an update of the uno-bridge may then also be needed. Will the Python people do it?
BASIC may be a rather outdated language and the StarBASIC IDE is not state of the art, there are less “nice tools” …

But StarBASIC is the programming tool LibreOffice comes with.

If StarBASIC one day will be replaced there should be hope that the LibreOffice team will also mind the transition/conversion …

I don’t actually know Python, and I’m using StarBASIC very limited. But if there should be need of custom programming I would firts try BASIC to come to a solution.

@Lupp: IHMO youre wrong, its not about waves, hype’s whatever…python still exist 25 Years – that, with respect, is in terms of IT a very long time, and its importance results from stable and robust development*** and not because of some kind being “the latest craze”…

***other reasons may be: Easy to learn, easy to test, …to develop, excellent Documentation, lot of ready to use third party stuff…

@karolus Yes! Python seems to be matured - and I already confessed that I don’t know more about it, except that I read and tried to understand a few code snippets published here and in the OpenOffice forum, some of them contributed by you. There I also made an observation: More than one times somebody (you again among them) suspected a Python upgrade to be the reason of a broken custom routine. I really don’t like BASIC. For the very little programming I do in LibO I’ll stick to it nonetheless.

I am looking for Python because 1) I am somewhat familiar with it and 2) I don’t want to learn LibreOffice Basic just for LibreOffice scripts.

1 Like

In short, YES it MUST be Python. The success of Excel with VBA scripting was due to Visual Basic being a known language used across many different software packages, able to integrate them together and automate them fully. If LibreOffice wants to be successful, it should integrate Python fully as a scripting language (even if it requires dumping StarBasic), because there are many more people who program in Python than there are who use Open/LibreOffice, and integration of Python and its other libraries will make OpenOffice Calc into a credible engineering tool. I have worked in Excel for decades and the power of its formatting and automation tools make it far, far superior to Calc for building spreadsheets that work like “apps” unto themselves, but embracing powerful and widespread scripting using open standards (VB.NET is not) is the way for Calc to make a credible run at challenging Excel’s dominance.

1 Like

I wouldn’t compete in experience, but there is something I don’t understand.
The way you praise VBA doesn’t emphasize its probably superior treasure of efficient predefined routines, but how it supports document automation. Python cannot do this and LibreOffice Basic doesn’t try. Both only build bridges to an API as it can be implemented for many additional programming languages/IDE.
VBA (as modified for different applications) isn’t just a programming language, but also an API.
The offsprings of StarOffice have their uno-API in this place.
Spreadsheets that work like apps? Well we can do this. But why should this be really relevant? Replace serious database apps as VBAstics seem to try again and again? Why?
And why did you use this extremely old thread to post your opinion with this respect?

Re. python and basic and frequency of languages: please note that the raspberry pi is a very popular credit card computer, introduced around 2012 in high school classes, now used around the world and with python as the default programming language. So chances are strong that a population of students, and others!, grow up with python nowadays, rather than basic.

A tutorial here : Interface-oriented programming in OpenOffice / LibreOffice : automate your office tasks with Python Macros

2 Likes

Yes, this is by far the best tutorial on Python macros in LibreOffice, and it should be given more prominence in the official documentation. I can recommend it wholeheartedly to anyone who needs to start programming LibreOffice with Python macros. Thank you for writing this.

Thank you! This looks very promising :slight_smile:

I was frustrated about the same thing as the OP, so made the time to publish my journey notes here: https://onesheep.org/scripting-libreoffice-python/
[edit: by @karolus ] the Link is dead now!

@JannieT1: some nice points :wink:

please correct the missing Indentation in dev.py and generally please follow the strong Convention of exactly four spaces per Indentation-level.

Have a look my answer in this thread

the link doesn’t work (obviously after 3 years…). Do you still have a copy of it? I’m very interested in it. Thanks!

Googling for it brought it up: Scripting LibreOffice with Python | OneSheep

Fwiw, that link is dead but the page is available in the WayBackMachine.

I made two libreoffice macros on python to rename and delete files. I hope It helps. Here is the link: GitHub - albcunha/libreoffice_macros: Python Script that inserts two macros for LibreOffice/Open Office: Rename files and Delete Files

Hallo!
How to start?
Currently your on the Stage:

  • no programming skills
  • no skills about this huge 200 MB Program nor its complicated Api

I’m only can give some advice: Start learning Python independent from Libreffice.
at some day in the Future you will be able to work with the “pieces spread over the web

some links:
tuturial
Start
not so hard as it looks
best available answer :wink:

1 Like

I do know Python loosely speaking. However, I have not found anything specific regarding Python used in conjunction to LibreOffice. Knowing Python can’t make it read LibreOffice sheets in its particular format can it?