Skip to main content

Posts

Showing posts from December, 2021

Basic Python macros in Libre Office Calc

There are only a few Libre Office Python macro examples in the internet. Here are some basic macros: Insert the current time in the cell D1: from datetime import datetime def insert_time(*args):   desktop = XSCRIPTCONTEXT.getDesktop()  model = desktop.getCurrentComponent()  active_sheet = model.CurrentController.ActiveSheet  now = datetime.now()  current_time = now.strftime("%H:%M:%S")  active_sheet.getCellByPosition(3,0).setFormula(current_time)  return Delete contents of the Column A: def delete_column_contents(*args):   desktop = XSCRIPTCONTEXT.getDesktop()  model = desktop.getCurrentComponent()  active_sheet = model.CurrentController.ActiveSheet  column = active_sheet.getCellByRangeName("A:A")  column.clearContents(1) #unfortunately this code deletes numbers only   return Place a cursor on the cell A11 (it is more like a workaround, partly derived from this forum ): def gotoCell(*args):   desktop = XSCRIPTCONTEXT...