MoreBasicFunctions  0.0.1
Java - UNO component that provides more basic functions
MoreBasicFunctions Documentation

MoreBasicFunctions - A LibreOffice Add-On written in Java that provides more basic functions.

Copyright (C) 2021 Julien Férard.

Questions: https://github.com/jferard/MoreBasicFunctions/discussions

Bug reports: https://github.com/jferard/MoreBasicFunctions/issues

Documentation: https://jferard.github.io/MoreBasicFunctions

Overview

On one hand, LibreOffice Basic is pretty limited, functions names are unusual (think of Mid!). On the other hand, Calc functions are powerful, but cumbersome to call because of a tedious syntax. Hence the idea of this add-on: MoreBasicFunctions exposes very common function as UNO services.

There is a major limitation: the services won't be available unless the add-on is installed. That means that your scripts won't be usable on a standard LibreOffice installation.

Use cases:

  • One PC script (typically personal script): install the add-on on the PC and use the services;
  • Prototype: the add-on will help you to write clean code;
  • Developer: the Tests service is mandatory on the developer PC but not on the end user PC.

There are several services: Tests, Strings, Characters, Regexes, Collections, Dates, Paths.

Tests

Some Junit like functions: assertTrue, assertFalse, assertEquals, assertNotEquals, assertArrayEquals, assertArrayNotEquals.

Strings

For string manipulation: reversed, split, join, lower/upper case, indexOf, substring...

Characters

For character manipulation Ord/Chr and identification: isLetter, isDigit...

Regexes

For regex usage: match, findAll/findFirst, replaceAll/replaceFirst.

Collections

For collections manipulation: sort, shuffle, min, max, avg, concat, flatten, times, chunks, randomElement, contains.

Dates

For date and time manipulation: now, strptime/strftime...

Paths

For path manipulation: list, recursiveList, split/join, parent, withExtension...

Example

To replace a string by another in a string using a Calc function call:

functionAccess = createUnoService("com.sun.star.sheet.FunctionAccess")  
MsgBox functionAccess.callFunction("SUBSTITUTE", Array("123123123", "3", "abc"))

Using MoreBasicFunctions:

Strings = createUnoService("com.github.jferard.mbfs.Strings")
MsgBox Strings.replace("123123123", "3", "abc")