How to use the Python scripting capabilities of LibreOffice Impress to set the background color of the table cell where the cursor is currently located

Hello everyone, I want to use the Python scripting capabilities of LibreOffice Impress to set the background color of the table cell where the cursor is currently located. I have been searching for a long time but couldn’t find a way to do this. Is there any solution? Thank you.

In Basic, you can do something like:

document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
dim args(0) as new com.sun.star.beans.PropertyValue
args(0).Name = "FillStyle"
args(0).Value = 1 ' Solid
dispatcher.executeDispatch(document, ".uno:FillStyle", "", 0, args)
dim args2(0) as new com.sun.star.beans.PropertyValue
args2(0).Name = "FillColor.Color"
args2(0).Value = 16776960
dispatcher.executeDispatch(document, ".uno:FillColor", "", 0, args2)

Can you try the equivalent of that in Python?

Thank you for your response. My use case might be more complex, not just setting the background color as simple as that. My real goal is to get the object of the table cell where the current cursor is located.

Hi mnhy520,

Something in the direction you ask:

ThisComponent.CurrentController.Selection.getByIndex(0).Model.Columns.getByIndex(0).getCellByPosition (0,0).setPropertyValue( "CharBackColor", 654456)

You can use Xray in de basic editor to find your way in all objects, properties, methods.
HTH,
Cor

Hi cornouws,
I’m not trying to get the cell at coordinate 0,0. What I’m trying to do is to get the cell where the current cursor is located, so I don’t know what the 0,0 coordinate refers to here.getCellByPosition (0,0)

Yes, I’m aware that my answer is only a hint in a direction.
I suggested to search with using Xray tool in basic. But to be honest, I do not have the idea that there is a something as a ‘current selection’ that refers to e.g. a text or a cell range, as is the case in Calc…

Okay, thank you for your help

1 Like

Having said that: it might well be that there is some interface/service provider that does give methods needed, but finding is the challenge (maybe with opengrock?)