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