LordMax LordMax - 1 year ago 77
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


EDIT -- the solution is

thank to Jim K

oCursor = modelDoc.Text.createTextCursor()
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 Source

Read the ParaStyleName:

style_name = cursor.getPropertyValue("ParaStyleName")
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download