Incorrect search result by FontWeight.BOLD style

Creating a macro - Writing a Script - Using the API

Incorrect search result by FontWeight.BOLD style

Postby karpo518 » Wed May 24, 2017 4:33 pm

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   Expand viewCollapse view
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)
karpo518
 
Posts: 15
Joined: Wed May 24, 2017 4:17 pm

Re: Incorrect search result by FontWeight.BOLD style

Postby Zizi64 » Sun Jul 09, 2017 7:20 am

Code: Select all   Expand viewCollapse view
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; LO4.4.7, LO5.3.7 on Win7x64Prof.
PortableApps, WinPenPack: LO3.3.0-LO5.4.2 and AOO4.1.3
Please, edit the topic's initial post, and add the word "[Solved]" at the beginning of the subject line - if your problem has been solved.
User avatar
Zizi64
Volunteer
 
Posts: 6076
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary


Return to Macros and UNO API

Who is online

Users browsing this forum: No registered users and 7 guests