Calc Python macro Hello World example 2025

LibreOffice Python macro documentation is very poor currently IMO so I’ll gather what I’ve found here.

Put this code into a file inside user/Scripts/python in the LO user profile directory:

import uno

document = XSCRIPTCONTEXT.getDocument()

def hello():
    active_sheet = document.CurrentController.ActiveSheet
    cell1 = active_sheet.getCellRangeByName("A1")
    cell1.String = "Hello world"

Run it with Tools > Macro > Run Macro > Library > My Macros > hello > Run

1 Like

Good code, concise.
Perhaps it was worth adding in the description “If the current document is a spreadsheet, then the specified text will appear in cell A1. In other cases, you can use the code HelloWorldPython from the LibreOffice Macros library”
image

1 Like

The LO user profile directory can usually be figured out easily from Options>LibreOffice>Paths. An example for a Windows python location would be:

C:\Users\username\AppData\Roaming\LibreOffice\4\user\Scripts\python

–Since we’re starting out with a complaint about documentation

1 Like