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/StylizeDocument.py (<class 'uno.com.sun.star.beans.UnknownPropertyException'>: Unknown property: CharPosture
File “/usr/lib/libreoffice/program/pythonscript.py”, line 905, in invoke
ret = self.func( *args )
File “/home/shemgp/.config/libreoffice/4/user/Scripts/python/StylizeDocument.py”, line 18, in search
search.setPropertyValue(‘CharPosture’, FontSlant.ITALIC)
))
Here’s my initial code:
def search():
class FontSlant():
from com.sun.star.awt.FontSlant 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:
return
for selIndex in range(0, selsFound.getCount()):
selFound = selsFound.getByIndex(selIndex)
selFound.setString("abc")