LordMax LordMax - 6 months ago 16
Python Question

How to get the Style name of a paragraph in a libreoffice document with a python macro?

I'm in need to create a python macro for some odt and ods documents.

I need to find the style name of a line and do some specific work for every style i found.

I can open the documents, get the line but not the style.
I've searched on internet and here but I found nothing.

Can someone help me with some piece of code?

N.B. I need a macro 'cause the list of odt files is in a calc workbook

Thanks




EDIT -- the solution is



thank to Jim K

oCursor = modelDoc.Text.createTextCursor()
oCursor.gotoStart(False)
sStyle = ''
#loop for cursor
while oCursor.gotoNextParagraph(False):
sStyle = sStyle + oCursor.getPropertyValue("ParaStyleName") + '\n'


The code give the name of all style used in paragraphs

Answer

Read the ParaStyleName:

style_name = cursor.getPropertyValue("ParaStyleName")