LibreOffice Calc · Formulas and analysis · Intermediate
Choose a Calc scripting language and understand ScriptForge
Distinguish Calc scripting languages, ScriptForge services and UNO objects using a read-only example with explicit runtime and testing limits.
Documentation-qualified; macro execution, optional providers and native persistence untested · Editorial standards
A scripting language, a macro organizer and ScriptForge are different parts of Calc automation. Choosing Python does not remove document-security requirements, and choosing ScriptForge does not make a script portable to Excel. This guide explains the boundaries before you decide whether automation is appropriate.
Scope: inspect first, do not enable execution
The language overview follows the free desktop Calc Guide 26.2, with English Windows/Linux menu names. The specific ScriptForge calls below are documented in online Help labelled 26.8, checked on 23 October 2026. They are not a claim of native 26.2 execution or identical support in older releases.
No macros were run, scripting providers installed or security settings changed for this article. Only inspect code and already-available tools unless benign local macro execution is separately authorized in your environment. Do not lower macro security, trust a downloaded document globally or install an extension to complete this lesson. There is no macro-enabled download or screenshot represented as native evidence.
Choose the layer deliberately
Guide 26.2 describes Basic, Python, JavaScript and BeanShell macros. Its recorder produces Basic, not a translation into all four languages. Tools > Macros > Run Macro selects available scripts, while Edit Macros opens the Basic IDE rather than a universal editor. Python and JavaScript editing require an external editor in the documented standard setup; BeanShell has a documented debug window.
ScriptForge is a service library for Basic and Python, not a fifth language and not a JavaScript/BeanShell compatibility wrapper. UNO is the underlying object/API model used to work with LibreOffice components. Similar-looking VBA syntax does not establish matching document objects or behavior.
If your task is simply repeating a short UI operation, read record and replay a document-owned macro instead. The example here is intentionally about reading explicit cell addresses, not another recorder lesson.
Check dependencies without installing them
A language listed in documentation does not prove that its provider exists in your package. Python Help explicitly warns that some GNU/Linux distributions make the Python scripting framework optional. Inspecting the application macro list for the supplied HelloWorldPython entry is a documented availability check; it is not a request to run that macro.
Treat missing Python, JavaScript or BeanShell organizers/providers as a stop for that language. Runtime packaging differs, and Java-dependent components require an appropriate existing runtime. This article does not certify a JavaScript engine, BeanShell runtime, Java installation or distribution-specific package combination. Do not infer JavaScript support merely because a web browser runs JavaScript, or Python integration merely because a system terminal has Python.
The Advanced options Help discusses JRE architecture compatibility and settings. It is background for an administrator’s dependency review, not instructions here to select a runtime, change class paths or install anything. Basic/ScriptForge code and Python/ScriptForge code still require their own supported environment.
Read an explicit range before writing automation
Create a disposable workbook manually with a sheet named Practice. Put the numbers 12, 8 and 5 in A1, A2 and A3. These are plain numbers, not numeric-looking strings, dates or error cells. Save the workbook and keep unrelated documents out of this test session.
The following Basic example illustrates reading those three cells. It is an original, documentation-qualified snippet, not a tested downloadable macro. ThisComponent must refer to this Calc workbook; a Writer document or unrelated component is not an acceptable substitute.
Sub InspectPracticeTotal
Dim book As Object
Dim total As Double
GlobalScope.BasicLibraries.LoadLibrary("ScriptForge")
Set book = CreateScriptService("Calc", ThisComponent)
total = book.GetValue("Practice.A1") _
+ book.GetValue("Practice.A2") _
+ book.GetValue("Practice.A3")
MsgBox total
Set book = book.Dispose()
End Sub
The 26.8 Calc service documentation supports loading ScriptForge, binding the service to ThisComponent, reading scalar values with GetValue and disposing the service. No cell-writing method is used. The intended numeric total is 25, independently checked as 12 + 8 + 5. If A2 is changed manually to 10, the expected total becomes 27. Those checks establish arithmetic only, not successful macro invocation, dialog formatting or lifecycle behavior.
Explicit sheet-qualified addresses prevent an active-sheet change from silently redirecting the example. They do not prevent the wrong workbook from being selected: verify both workbook and sheet before any authorized run. For a real application, add document-type and input-type checks before extending the snippet; do not present this three-number exercise as a general validation framework.
In Python, the documented entry is from scriptforge import CreateScriptService. That does not mean importing it in an arbitrary system Python interpreter connects to Calc. The Python provider context, document selection and module availability are separate prerequisites. A Python execution procedure is intentionally not supplied or claimed tested here.
Inspect objects without guessing API names
Guide 26.2 describes Tools > Development Tools as the built-in object inspector. In an already-available installation, select a harmless cell in the scratch workbook and inspect the document object model, or use Current Selection to inspect that selected object. Compare the listed interfaces, services, properties and methods with the object you intended to access.
This is a discovery step, not permission to invoke arbitrary methods. Do not modify properties just because the inspector reveals them. A useful inspection note records the selected object and the relevant service/interface name, so later API research is grounded in the actual target rather than an Excel object name guessed from memory.
Troubleshooting and acceptance boundaries
- ScriptForge is unknown: check the library-loading statement and documented version support. Stop if the library/provider is absent; changing trust settings will not supply a missing API.
- The wrong result appears: verify the workbook binding and all three cell values. A date serial or text value violates this fixture, even if it can be coerced into a number.
- The Basic IDE opens instead of Python: that is not proof the Python script is broken. Use the language’s documented organizer/editor workflow, subject to existing authorization.
- A shared workbook loses its automation: distinguish document-contained macros from user-profile macros. Do not assume a colleague has your local providers, libraries or permissions.
For release acceptance, record the exact application build, OS, provider availability, reviewed code hash, input values and actual outputs. Save/reopen behavior and macro portability need separate testing. Until those checks happen, this remains a source-backed orientation and example, not native execution evidence.
Sources
Calc Guide 26.2, Chapter 14 covers the languages, ScriptForge and inspector. SFDocuments.Calc Help, labelled 26.8 documents the example’s service calls. Python scripts Help, labelled 26.8 documents optional GNU/Linux provider availability. Advanced options Help, labelled 26.8 covers Java runtime configuration boundaries.