Need help to modify Python macro

Joined
Jan 24, 2025
Messages
3
Reaction score
0
I want to use this macro in LibreOffice Calc spreadsheet but instead get “Button Name”

I what to get “Button Label”.

Can anyone help me change this code? Thank you

def insert_button_name(oEvent):
"""Insert the button name into the next empty row in column E.
Update B2 to track the next available row number.
"""
oButton = oEvent.Source
button_name = oButton.getModel().getName()
oDoc = XSCRIPTCONTEXT.getDocument()
oSheet = oDoc.getCurrentController().getActiveSheet()
oCell = oSheet.getCellRangeByName("B2")
COLUMN_E = 4
row_num = oCell.getValue() - 1
oTargetCell = oSheet.getCellByPosition(COLUMN_E, id)
oTargetCell.setString(button_name)
oCell.setValue(oCell.getValue() + 1)
 
Joined
Jan 14, 2025
Messages
16
Reaction score
3
I want to use this macro in LibreOffice Calc spreadsheet but instead get “Button Name”

I what to get “Button Label”.

Can anyone help me change this code? Thank you

def insert_button_name(oEvent):
"""Insert the button name into the next empty row in column E.
Update B2 to track the next available row number.
"""
oButton = oEvent.Source
button_name = oButton.getModel().getName()
oDoc = XSCRIPTCONTEXT.getDocument()
oSheet = oDoc.getCurrentController().getActiveSheet()
oCell = oSheet.getCellRangeByName("B2")
COLUMN_E = 4
row_num = oCell.getValue() - 1
oTargetCell = oSheet.getCellByPosition(COLUMN_E, id)
oTargetCell.setString(button_name)
oCell.setValue(oCell.getValue() + 1)
You need to adjust the code to access the button's label property. The getLabel() method can be utilized for this purpose.
Example:
Code:
button_name = oButton.getModel().getLabel()
 
Joined
Jan 24, 2025
Messages
3
Reaction score
0
You need to adjust the code to access the button's label property. The getLabel() method can be utilized for this purpose.
Example:
Code:
button_name = oButton.getModel().getLabel()
I modified as suggested in Thonny
 
Joined
Jan 24, 2025
Messages
3
Reaction score
0
Thank you for your reply.
Following your suggesting I modified in Thonny. run the script in Calc it gave a error.
I don’t understand this error can you please help to fix this.
Thank you


Com.sun.star.uno.RuntimeException:Error during invoking function
insert_button_name in module file:/// home/luis/.config/libreoffice/4/user/
Scripts/python/Incrementcells01.py(<class ‘AttributeError’>: getLabel

File “/usr/lib/libreoffice/program/pythonscript.py”, line 916, in invoke
ret = self.func( *args )
^^^^^^^^^^^^^^^^^^^^^^^^^^^^

File “/home/luis/.config/libreoffice/4/user/Scripts/python/
Incrementcells01.py”, line 6, in insert_button_name

button_name = oButton.getModel().getLabel()
^^^^^^^^^^^^^^^^^^^^^^^^^^
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,196
Messages
2,571,036
Members
47,631
Latest member
kukuh

Latest Threads

Top