[Solved] Filter from paragraph property

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
Bastien
Posts: 61
Joined: Mon May 12, 2014 2:45 pm

[Solved] Filter from paragraph property

Post by Bastien »

I've got a writer doc wich contains some paragraph in bold character. I need to parse all the paragraph (wich is simple) and apply a special action for them.
Here is the python code I wrote for now.

Code: Select all

        while tCursor.gotoNextParagraph(True):
        mri(ctx, tCursor.CharWeight)
        tCursor.collapseToEnd()
The selection is ok. It parses each paragraph, but introspection tool Mri returns "void" for CharWeight property. How could I test wether it's a bold or normal paragraph?
Last edited by Bastien on Wed Mar 06, 2019 10:26 am, edited 1 time in total.
LibreOffice 6.2.3.2 on Ubuntu 19.04
User avatar
Zizi64
Volunteer
Posts: 11359
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Filter from paragraph property

Post by Zizi64 »

Use different paragraph styles and check the applied style and/or the properties of the applied paragraph style.
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Filter from paragraph property

Post by Villeroy »

The property value is void when the selected section has more than one value for that property.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Bastien
Posts: 61
Joined: Mon May 12, 2014 2:45 pm

Re: Filter from paragraph property

Post by Bastien »

Unfortunately, the documents I work on come from so many source that paragraph style are not coherent. The only criteria is bold or normal.
LibreOffice 6.2.3.2 on Ubuntu 19.04
User avatar
RoryOF
Moderator
Posts: 34612
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: Filter from paragraph property

Post by RoryOF »

You may have to parse the paragraph on a word by word basis and apply some criterion to decide if that paragraph has sufficient of "bold" to qualify for treatment - perhaps first word/last word in bold might be sufficient.
Apache OpenOffice 4.1.15 on Xubuntu 22.04.4 LTS
FJCC
Moderator
Posts: 9274
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

Re: Filter from paragraph property

Post by FJCC »

You can create an enumeration of paragraphs from the Text of the document. Each paragraph is made up of Portions of uniform formatting. A Portion will have a single CharWeight value. In Basic

Code: Select all

oText = ThisComponent.Text
oP_Enum = oText.createEnumeration()
While oP_Enum.hasMoreElements()
	oP = oP_Enum.nextElement()
	oPor_Enum = oP.createEnumeration()
	While oPor_Enum.hasMoreElements
		oPor = oPor_Enum.nextElement()
		if oPor.CharWeight > 100 then
			print oPor.string
		end If
	Wend
Wend
OpenOffice 4.1 on Windows 10 and Linux Mint
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
Bastien
Posts: 61
Joined: Mon May 12, 2014 2:45 pm

Re: Filter from paragraph property

Post by Bastien »

To FJCC
This is exactly what I was looking for. I don't understand why you create a second enumeration. It works in Python like this:

Code: Select all

    stext = document.Text
    stext_enum = stext.createEnumeration()

    while stext_enum.hasMoreElements():
        paragraph = stext_enum.nextElement()
        if paragraph.CharWeight > 100:
            msgbox(parentwin, paragraph.String, "Check if it works!")
LibreOffice 6.2.3.2 on Ubuntu 19.04
JeJe
Volunteer
Posts: 2779
Joined: Wed Mar 09, 2016 2:40 pm

Re: [Solved] Filter from paragraph property

Post by JeJe »

FJCC's second enumeration would be needed if the paragraph contained parts that were bold and parts that weren't. If its the whole paragraph that's bold then you just need to enumerate those.
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
Post Reply