Search code examples
pythonopenoffice-writerpyuno

How to set Text Background Color using PyUNO with OpenOffice


I have a python script that successfully does a search and replace in an OpenOffice Writer document using PyUNO. I am able to set the CharColor of the replaced text ok but am unable to set the BackColor (background color).

found.setPropertyValue( "CharColor", 16776960  ) //OK
found.setPropertyValue( "BackColor", 16776960  ) //NOT OK

'found' variable is the result of a call to document.findFirst method I am not 100% sure what type of object it is??

I get the error "com.sun.star.beans.UnknownPropertyException: Unknown property: BackColor"

BackColor is used in a number of examples as it applies to Table Cells but does not seem to work for plain text. Can anyone please tell me what property to set, or if it's even posible?

Thanks


Solution

  • I think property name is CharBackColor not BackColor.

    P.S. you could directly use properties in Python instead of calling setPropertyValue method for example

    found.CharColor = 16776960
    found.CharBackColor = 16776960