Question on Feature Availability [macros, automations]

Hello community,

First, I apologize if my first posts do not fully comply with the forum’s etiquette, I’m new here and I will try to limit my posts to a single subject.

Having said that, I think it’s necessary to give a background since I don’t believe this is superfluous information, but it would rather help mods and admins better understand my use cases. I’ll try to keep things short.

Background

I’m a new user switching from Ms Office and I’m facing a few challenges to completely get off Ms platform since I am a power user of Ms Excel, its macros and its Power Query features. Unfortunately however, I’m not a full stack developer so I can’t work on multiple IDEs so I’m totally reliant on whatever IDE the platform provides me.

I do have a lot of automated workflows already on Microsoft Office and I would like to carry them over for me and my staff to Libre Office, since it’s the best I’ve tested thus far. My automations are heavily reliant on Excel’s ListObject object since it provides my data with structure instead of having to scrape through the worksheets and identify ranges, headers and then loading them into arrays, and dictionaries.

I have searched the documentation and help on this matter, but the documentation leaves a lot to be desired for those looking for advanced feature or details.

I thought the Libre Office support forum could point me out to these resources so I can read the documentation for myself in case it exists.

List of Features

  1. I noticed that defined ranges which is equivalent to Excel’s tables do not support relative row references such as [@Column1]. I scanned through the documentation on defined ranges and found nothing on this subject.

  2. Is there a way for defined ranges to automatically update their ranges? I know I can

  3. I see that Libre Office supports JavaScript from Macros > Tools > Organize Macros. However, I couldn’t figure how to use it and also, the documentation only how to run python but not JavaScript. Are there any extensions that I need to install first?

  4. I couldn’t find the documentation for defined range object in the documentation, which leads me to my biggest issue which is next.

  5. I recorded a macro to learn more about the objects, but the resulting script looks like BASIC isn’t integrated to the runtime but rather, it uses an API of another scripting language (I assume its BeanShell but I could be wrong) and the result is very cryptic:

sub Main
rem ----------------------------------------------------------------------
rem define variables
dim document   as object
dim dispatcher as object
rem ----------------------------------------------------------------------
rem get access to the document
document   = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")

rem ----------------------------------------------------------------------
dim args1(1) as new com.sun.star.beans.PropertyValue
args1(0).Name = "By"
args1(0).Value = 1
args1(1).Name = "Sel"
args1(1).Value = false

dispatcher.executeDispatch(document, ".uno:GoDown", "", 0, args1())

rem ----------------------------------------------------------------------
dim args2(1) as new com.sun.star.beans.PropertyValue
args2(0).Name = "By"
args2(0).Value = 1
args2(1).Name = "Sel"
args2(1).Value = false

dispatcher.executeDispatch(document, ".uno:GoRight", "", 0, args2())

rem ----------------------------------------------------------------------
dispatcher.executeDispatch(document, ".uno:SelectColumn", "", 0, Array())

rem ----------------------------------------------------------------------
dim args4(0) as new com.sun.star.beans.PropertyValue
args4(0).Name = "Flags"
args4(0).Value = "C"

dispatcher.executeDispatch(document, ".uno:InsertCell", "", 0, args4())

end sub

Is there a way to expose the document objects at runtime, or is using this API the only way to interact with calc documents objects?

Welcome @emkfardan!

I know what you’re talking about, this is what everyone who switches from MS Office to LibreOffice faces. The first thing a newbie does is turn on the macro recorder, perform actions and sincerely believe that the generated code will be readable. Broken hopes, tears, confusion…

The thing is that the built-in LibreOffice macro recorder uses only one command from the entire Office API: “Run a user interface element with these parameters”. Each menu item has a unique name like .uno:Copy or .uno:SaveAs. And the parameters are a regular array with name-value pairs. This is completely unreadable and almost impossible to edit. Unlike VBA, which generates quite decent script code.

Please watch this - https://youtu.be/DHgblImh4lQ

Don’t forget to turn on the subtitles - all the explanations for the video are there.

There is another source of knowledge about LibreOffice programming. I have written about this so many times to different people that I am just repeating it again now.
Andrew Pitonyak once collected a lot of working code from different forums, provided it with detailed comments and compiled it into one book. It was just a draft for his future detailed guides to OpenOffice/LibreOffice programming, but this book, in my opinion, turned out to be the best.
You don’t have to read it from start to finish, it’s not a textbook, it’s a “cookbook” - you pick a topic from the table of contents that’s relevant to your current task, quickly read three or four paragraphs of explanation, copy the listing into your project, make sure everything works, and read the code to understand how it works. I learned it myself after VBA, I know.

2 Likes

Definitely do not overlook using XRay or MRI. That is the absolute key…just have a macro XRay the object of interest and look around for awhile to familiarize yourself with it. Searches on AskLO will lead you to more about these. They are like a live version of the F2 object browser in Excel.

A pavement-pounding perspective is to ask Gemini, etc., for a macro, double check the resulting calls at LO IDL Reference, and accept that AI will probably hallucinate API calls about half the time.

Using XRay.ods (17.3 KB)

Development Tools

which are extensions …
which would be found at https://extensions.libreoffice.org

but that would be too simple :expressionless:
Xray can't find help in SDK or online

This extension ( LibrePythonista) may be useful. https://extensions.libreoffice.org/en/extensions/show/99231