https://api.libreoffice.org/docs/idl/ref/namespacecom_1_1sun_1_1star_1_1sheet_1_1ConditionFormatOperator.html
To create conditional formatting through python macro, I need to use operators:
BEGINS_WITH
CONTAINS
I tried to reproduce the idea of this post but it didn’t work
import uno
from com.sun.star.beans import PropertyValue
#from com.sun.star.sheet.ConditionOperator import EQUAL
#from com.sun.star.sheet.ConditionOperator import GREATER
# https://api.libreoffice.org/docs/idl/ref/namespacecom_1_1sun_1_1star_1_1sheet_1_1ConditionFormatOperator.html
from com.sun.star.sheet.ConditionFormatOperator import BEGINS_WITH
from com.sun.star.sheet.ConditionFormatOperator import CONTAINS
def main(*args):
doc = XSCRIPTCONTEXT.getDocument()
rango = doc.Sheets[0]['A1:A10']
cf = rango.ConditionalFormat
cf.clear()
args = dict(
Operator = BEGINS_WITH,
Formula1 = '"(00)"',
StyleName = 'Good'
)
pv = [PropertyValue(Name=n, Value=v) for n, v in args.items()]
cf.addNew(pv)
rango.ConditionalFormat = cf
args = dict(
Operator = CONTAINS,
Formula1 = '"Unidade"',
StyleName = 'Bad',
)
pv = [PropertyValue(Name=n, Value=v) for n, v in args.items()]
cf.addNew(pv)
rango.ConditionalFormat = cf
return
How do I do what I need?
https://www.openoffice.org/api/docs/common/ref/com/sun/star/sheet/ConditionOperator.html
Complement
In this image I created the conditional formatting manually. This is how I would like the python macro to return.
This is the result of the code above, Begins_with and Contains is not applied. Instead select the first option in the list: ‘is equal to’ and the value is blank:
file test:
test1.ods (11,9,KB)