Writer/ReplAttributes

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
BubikolRamios
Posts: 91
Joined: Sat Jan 04, 2014 1:28 pm

Writer/ReplAttributes

Post by BubikolRamios »

This replaces text as desired, simultaneously I want to replaced text becomes BOLD (and in next loop BOLD to be skipped). Does not work for some reason.
Replaces text, no effect on style.

Code: Select all

For i= Lbound(matrix,1) To Ubound(matrix,1)
     oReplace.SearchString = matrix(i)(0)          ' Regular expression. Match any text
     oReplace.ReplaceString =  matrix(i)(1)           'Note the & places the found text back
    ' msgbox ( matrix(i)(0))
    ' oReplace.SearchRegularExpression=False  Use regular expressions
    oReplace.searchStyles=True             'We want to search styles
    
    REM This is the attribute to find
    SrchAttributes(0).Name = "CharWeight"
    SrchAttributes(0).Name = "CharStyleName"
    SrchAttributes(0).Value =com.sun.star.awt.FontWeight.NORMAL' tryed DONTKNOW, no difference


    REM This is the attribute to replace it with
    ReplAttributes(0).Name = "CharWeight"
    ReplAttributes(0).Name = "CharStyleName"
    ReplAttributes(0).Value =com.sun.star.awt.FontWeight.BOLD
 

    REM Set the attributes in the replace descriptor
    oReplace.SetSearchAttributes(SrchAttributes())
    oReplace.SetReplaceAttributes(ReplAttributes())
    
    
    
    
     oReplace.searchAll=True               ' Do the entire document
  
     oDoc.replaceAll(oReplace)
  Next i

OPen office 4.1.5/ win 7
User avatar
Zizi64
Volunteer
Posts: 11359
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: writer/ReplAttributes

Post by Zizi64 »

My opinion:
It is better to use the styles (Paragraph Styles, Character Styles and others) instead of the usage of a macro code to change some manually adjusted properties in a document.
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