Replace text / skip formated text

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

Replace text / skip formated text

Post by BubikolRamios »

Code: Select all

   oReplace = oDoc.createReplaceDescriptor()

  For i= Lbound(matrix,1) To Ubound(matrix,1)
    
     oReplace.SearchString = matrix(i)(0)           'Regular expression. Match any text
     oReplace.ReplaceString =  matrix(i)(1)           
     'msgbox ( matrix(i)(0))
     oReplace.SearchRegularExpression=False  'Use regular expressions
     oReplace.SearchCaseSensitive = False
     'oReplace.searchStyles=True             'We want to search styles
     oReplace.searchAll=True                'Do the entire document
assuming matrix has pairs like [[foo][foo1]]

How about not replacing if foo is entirely red or just part of it red ?
OPen office 4.1.5/ win 7
JeJe
Volunteer
Posts: 2764
Joined: Wed Mar 09, 2016 2:40 pm

Re: Replace text / skip formated text

Post by JeJe »

Do a search (not a search replace). Go through all the results and only replace the ones you want.

Edit:
You can do another search with the selection returned by a search - but if I remember rightly you have to use the dispatch helper to do a search within a selection.
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
Post Reply