Incorrect search result by FontWeight.BOLD style

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
karpo518
Posts: 15
Joined: Wed May 24, 2017 4:17 pm

Incorrect search result by FontWeight.BOLD style

Post by karpo518 »

I want to find substring by text styles. I try to search some characters by styles. I got correct substring, when i search by CharBackColor(or other) style.
But i got incorected result, when i search by CharWeight. Instead of substring, I got the whole paragraph, which has a bold text. Why is it happens?

Code: Select all

import uno,sys,re
from com.sun.star.awt import FontWeight
from com.sun.star.beans import PropertyValue
..
oSearch = oDoc.createSearchDescriptor()
oSearch.SearchString = oSearchString
oSearch.SearchCaseSensitive = False
oSearch.SearchRegularExpression = True
oSearch.SearchStyles = True
oSearch.SearchWords = False
SrchAttributes = []
prop = PropertyValue()
prop.Name = 'CharWeight'
prop.Value = FontWeight.BOLD
SrchAttributes.append(prop) 
oSearch.setSearchAttributes(SrchAttributes)
oFound = oDoc.findNext(oLCurs, oSearch)
while oFound != False:
    if oDoc.Text.compareRegionEnds(oFound, oRCurs) <= 0:
        break
    oString = oFound.getString()
    msgBox(oString)
    oFound.setString('')
    oFound = oDoc.findNext(oFound.End, oSearch)
Last edited by RoryOF on Wed May 24, 2017 4:35 pm, edited 1 time in total.
Reason: Corrected typo in Subject [RoryOF, Moderator]
Libre Office 5.1.6.2, Linux Mint 18 (64 bit)
User avatar
Zizi64
Volunteer
Posts: 11353
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Incorrect search result by FontWeight.BOLD style

Post by Zizi64 »

Code: Select all

oSearch.SearchStyles = True
oSearch.SearchWords = False
Maybe the result is an applied PARAGRAPH STYLE. The parapgraph style is always applied to a whole paragraph.
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.
Post Reply