Ask Your Question
3

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

asked 2015-04-11 17:07:48 +0200

plrrrrr gravatar image

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?

edit retag flag offensive close merge delete

Comments

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.

Lupp gravatar imageLupp ( 2015-04-12 12:29:53 +0200 )edit

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 gravatar imageLupp ( 2015-04-12 13:00:24 +0200 )edit

@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 gravatar imagekarolus ( 2015-04-12 17:20:26 +0200 )edit

@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.

Lupp gravatar imageLupp ( 2015-04-12 17:36:26 +0200 )edit

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.

plrrrrr gravatar imageplrrrrr ( 2015-04-12 20:26:17 +0200 )edit

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.

AcousticTheory gravatar imageAcousticTheory ( 2020-04-28 17:48:34 +0200 )edit

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?

Lupp gravatar imageLupp ( 2020-04-28 20:53:49 +0200 )edit

7 Answers

Sort by » oldest newest most voted
6

answered 2015-12-06 19:53:20 +0200

Christopher5106 gravatar image
edit flag offensive delete link more

Comments

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.

steko gravatar imagesteko ( 2016-04-18 13:44:32 +0200 )edit

Thank you! This looks very promising :)

houseisfun gravatar imagehouseisfun ( 2016-08-07 12:01:15 +0200 )edit
2

answered 2017-02-02 14:24:07 +0200

Jannie T gravatar image

I was frustrated about the same thing as the OP, so made the time to publish my journey notes here: https://onesheep.org/scripting-libreo...

edit flag offensive delete link more

Comments

@Jannie T: some nice points ;-) …

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

karolus gravatar imagekarolus ( 2017-02-02 15:18:11 +0200 )edit

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

linuxyz gravatar imagelinuxyz ( 2020-05-09 12:41:45 +0200 )edit
2

answered 2017-08-12 06:46:57 +0200

pysb gravatar image

I made two libreoffice macros on python to rename and delete files. I hope It helps. Here is the link: https://github.com/albcunha/libreoffice_macros

edit flag offensive delete link more
1

answered 2015-07-09 10:16:58 +0200

eelco gravatar image
edit flag offensive delete link more

Comments

You link provide no new informations, the HelloWorld-example is already included in ...libreoffice/share/Scripts/python/...

karolus gravatar imagekarolus ( 2015-07-09 11:16:48 +0200 )edit

this is a good example and exemplifies my impression that the LibreOffice flavor of Python is fairly unPythonic dialect of Java. Would help to have a reference of what are the major objects/methods to invoke to get started, the equivalent in LO Basic of ThisComponentThisDatabaseDocument and dbg_methods, etc.

doug gravatar imagedoug ( 2015-07-10 02:55:22 +0200 )edit
1

answered 2015-04-12 18:04:09 +0200

karolus gravatar image

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 ;-)

edit flag offensive delete link more

Comments

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?

plrrrrr gravatar imageplrrrrr ( 2015-04-12 20:25:03 +0200 )edit

Of Course with python you can also read|write .odf in general inclusive .ods in detail without any soffice at hand.
this thirdparty-tool

karolus gravatar imagekarolus ( 2015-04-12 22:15:33 +0200 )edit
1

answered 2018-12-20 02:55:34 +0200

erAck gravatar image

Updating this old and maybe outdated but cross-referenced Q&A with a pointer to my (occasionally maintained) LibreOffice Scripting link collection.

edit flag offensive delete link more
0

answered 2019-04-30 12:32:56 +0200

Check my profile in this forum for extra Python information

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

2 followers

Stats

Asked: 2015-04-11 17:07:48 +0200

Seen: 56,346 times

Last updated: Apr 30 '19