How to search font styles using python

asked 2019-02-10 12:18:13 +0100

shemgp gravatar image

I would like to search for a characters/words with a given font style and set it's paragraph style using python macro. But I'm stuck with:

Unknown property: CharPosture (Error during invoking function search in module file:///home/shemgp/.config/libreoffice/4/user/Scripts/python/ (<class ''>: Unknown property: CharPosture

File "/usr/lib/libreoffice/program/", line 905, in invoke ret = self.func( *args ) File "/home/shemgp/.config/libreoffice/4/user/Scripts/python/", line 18, in search search.setPropertyValue('CharPosture', FontSlant.ITALIC) ))

Here's my initial code:

def search():
    class FontSlant():
        from import (NONE, ITALIC,)
    document = XSCRIPTCONTEXT.getDocument()
    search = document.createSearchDescriptor()
    search.SearchString = "(.*)"
    search.SearchAll = True
    search.SearchWords = True
    search.SearchRegularExpression = True
    search.SearchCaseSensitive = False
    search.setPropertyValue('CharPosture', FontSlant.ITALIC)
    selsFound = document.findAll(search)
    if selsFound.getCount() == 0:
    for selIndex in range(0, selsFound.getCount()):
                selFound = selsFound.getByIndex(selIndex)
edit retag flag offensive close merge delete