Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

As I'm working in python and I find there are far fewer python examples than LibreOffice Basic examples, I will add my python solution here for others as well. This one is based on @Ratslinger's solution, with a minor tweak as explained in the snippet's coment lines:

def BeforeUpdating (*args):
    # XSCRIPTCONTEXT is a global variable passed on to scripts by LibreOffice
    oDoc = XSCRIPTCONTEXT.getDocument()
    oForm = oDoc.DrawPage.Forms.getByName("YOUR_INTERNAL_FORM_NAME")
    # Note 'oForm.Columns'/'oColumn.getByIndex(INDEX)' should work as well below
    # I use the alternative 'oForm.findColumn' as I find it easier
    # to remember a column name than a column index
    # Important caveat though:
    # oColumn.getByIndex(idx) expects an idx value that starts from 0
    # oForm.getString(idx) expects an idx value that starts from 1
    # oForm.findColumn("NAME") returns an idx valud that starts from 1
    colIdx = oForm.findColumn ("TABLE_COLUMN_NAME")
    print (oForm.getString(colIdx))