2
I am really new to this and OpenOffice Developer's Guide is too difficult for me to understand or I'd help myself.
I have a large number of rows with data and in each row I want a button that would trigger a particular macro rowMacro
. That macro will analyze/modify data in that particular row. For simplicity, let's say it it just writes an arbitrary string somewhere in the row:
import uno
oDoc = XSCRIPTCONTEXT.getDocument()
def rowMacro(*args):
oSheet = oDoc.CurrentController.ActiveSheet
oCell1 = oSheet.getCellRangeByName("A4")
CurContr=oDoc.getCurrentController().getSelection()
oCell1.String = "Tada!"
I don't want to create a dozen of separate near-identical scripts for each row - so no rowMacroRowA
triggered by a specific button in row A, etc. I'd rather have a number of buttons all triggering the same python macro. That macro somehow needs to determine which button was used (each button has a unique name) and modify only the appropriate row. So I need to figure out the way to get a button name in python (I'll know how to handle it from there).
I stumbled upon a webpage with an excerpt like this:
# get the sheet
accueil_sheet = model.Sheets.getByName("Accueil")
# access the draw page
oDrawPage = accueil_sheet.DrawPage
# count the number of form
oDrawPage.getForms().getCount()
# get the list box of the control element
ListBox = oDrawPage.getForms().getByIndex(0).getByName("Listbox")
# get the list box item list
ListBox.StringItemList
# get the list box controller
ListBoxCtrl = model.getCurrentController().getControl(ListBox)
# get the selected items:
ListBoxCtrl.SelectedItems
but I do not know how to deduct my problem's solution from that.
To summarize:
- How to get a name of a button that was used to trigger a macro?
- Better yet - how to get its position, in particular a row? (this one I'd rather figure out on my own if you push me in the right direction).
That's it! Thanks a dozen. No follow-up needed, the example helped me a lot. – user2551153 – 2017-03-23T13:44:06.773