0

I work on a Calc file, with several tabs. Some are used to store datas (like SQL tables).

With a python macro, I want to fill a ComboBox "Classes" using the datas in one of these tables.

enter image description here

My code :

bas = CreateScriptService('SFDocuments.Document')
formulaire = bas.Forms(F_sheetName, 'Formulaire')
comboBoxClasses = formulaire.Controls(O_classes)

I'd like to be able to do something like this :

comboBoxClasses.addItem("class1")
comboBoxClasses.addItem("class2")

The function addItem does not exist. What should I use instead ?

asked Jun 27, 2025 at 8:20
8
  • in Python you can use dir() to check what functions and properties has objects. Maybe print( dir(comboBoxClasses) ) could show you what functions you can use. Commented Jun 27, 2025 at 13:25
  • using Google I found example ListExtractorExample and this code may suggest that you have to use .Value and later you can use standard .append(), .insert() to add elements and .pop() to get value. But I didn't test it. comboBoxClasses.Value.append("class1") Commented Jun 27, 2025 at 13:26
  • dir says the only property is Controls, and on Controls, there is '__ call __' Commented Jun 27, 2025 at 13:52
  • I'm trying Value Commented Jun 27, 2025 at 13:53
  • 1
    @furas: The example you linked is for dialogs, not spreadsheet forms, and those have different interfaces. Also, dir() cannot see through the proxies, so it won't help. Commented Jun 27, 2025 at 15:47

1 Answer 1

1

The code you've shown uses the ScriptForge library. To me, that seems unnecessarily difficult.

With plain python-uno, you can use an introspection tool such as MRI to view properties, like an improved dir(). MRI shows a method called insertItemText() that takes two arguments, the position and text.

sheet = XSCRIPTCONTEXT.getDocument().getSheets().getByIndex(0)
form = sheet.getDrawPage().getForms().getByName("Formulaire")
comboBoxClasses = form.getByName("ComboBoxClasses")
comboBoxClasses.insertItemText(0, "History")

If your code already depends heavily on ScriptForge, then you could back out into the ordinary UNO world like this:

from scriptforge import CreateScriptService
bas = CreateScriptService('SFDocuments.Document')
formulaire = bas.Forms('Sheet1', 'Formulaire')
comboBoxClasses_SF = formulaire.Controls('ComboBoxClasses')
comboBoxClasses = comboBoxClasses_SF.XControlModel
comboBoxClasses.insertItemText(1, "Science")

Otherwise, if you really want to learn how to use ScriptForge, here is the documentation I found for form controls: https://help.libreoffice.org/latest/en-US/text/sbasic/shared/03/sf_formcontrol.html, but it doesn't show how to insert items. I'm not sure if there is a way to investigate properties — MRI will not work on the library.

answered Jun 27, 2025 at 15:21
Sign up to request clarification or add additional context in comments.

1 Comment

The first script works. Thank you very much !

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.