[mdlug] Macro Language in Libre Office

Dr. Robert Meier list1c30fe42 at bellsouth.net
Tue May 30 12:28:12 EDT 2017


Musichall,

Though LibreOffice supports both python and basic,
I've never seen either used, except as a kludge or learning experience.

I suggest that you take a look at the LibreOffice API
(https://help.libreoffice.org/Common/Integrating_new_UNO_components),
with regard to Calc custom functions and Writer custom styles.

I've not written either myself, but my colleagues have.

<AFAIK>
The LibreOffice API is compatible with C++, java, Python, Basic,
/bin/sh, ...  I suggest you use what you are familiar with,
or if none are familiar, start with /bin/sh (actually bash).

The unix philosophy (https://en.wikipedia.org/wiki/
/Unix_philosophy#Eric_Raymond.E2.80.99s_17_Unix_Rules) includes
  Rule of Modularity - replaceable parts
  Rule of Separation - dont interlace render and content
  Rule of Generation - avoid writing source twice, compile instead
  Rule of Extensibility - well-defined interfaces
VBA code is integrated (non-separable) into monolithic (non-modular)
Word and Excel, and consequently complex (to handle poorly-defined
excel and word corner cases) requiring hand entry (to fit each
placement).
</AFAIK>

<IMHO>
As a way to get started migrating, I suggest you pick three
simple usage examples for your current code.  For your
selection, try to ignore which and how much VBA code is involved.
Select instead some "act" that you can describe in a single
English sentence, that you normally accomplish in less than a
minute, and that you do often enough that you don't even remember
the relevant underlying VBA code.

Start reading the LibreOffice API documentation
(http://api.libreoffice.org), As you read, try to duplicate
some of the documented examples.  I suspect you will quickly
learn to satisfy at least one of your above-selected usages.
After you have solved one (or all three) usage, you will
likely be able to plan how to solve increasingly more usages
until you have successfully migrated.

You should find that much of the API code you write will
be reusable (making the total code volume far less than
the replaced VBA) and portable (easily modified or used as-is
for web, database, ...)
</IMHO>

<IMHO>
If you still want to use Excel-Word-VBA style integrated
code, I suggest that Libreoffice basic represents
less of a labor investment to be lost.
</IMHO>

Hopefully helpful,
--
drb

On 05/27/2017 03:19 PM, musichall at juno.com wrote:
> Since I am migrating from Windows to some flavor/variant of Linux,
> I am considering engaging an effort to migrate VBA code (both for MS
Word and MS Excel)
> to something corresponding to what is more native to the Linux realm.

> The work in Excel involves reading values (both numbers and
corresponding text) into an 'array',
> sorting the "array" (I use the word array more as a discussion concept
rather than as a specific method,
> but not to preclude/exclude its use), making some calculations with
the numbers,
> then modifying (i.e. entering) some other blank cells with the results.

> The work in Word involves primarily page layout of given text:
> text organizing/manipulation or rather paragraph manipulation, keeping
the text the same,
> but modifying presentation e.g. bold, underline, etc.

> I have been looking into both Mint and Fedora (more at Mint at the
moment for this exercise) - both recent releases.
> Both releases appear to have included LibreOffice (LO).
> That's fine. With VBA, I have already learned that 'mind-set' which
applies to both applications,
> and I am looking for whatever (single) appropriate language to use in LO.

> My question is essentially which macro language to pursue for this
work: LibreOffice Basic or Python?
> From what I've been able to gather, Python is more "powerful"
(whatever that means),
> though LibreOffice Basic is supposed to be easier to transition to
from VBA.
> What more might I consider using Python for? Thanks in advance for
your help.



More information about the mdlug mailing list