If I record a macro in Writer I can limit the search to selected text.
args1(0).Name = "SearchItem.SearchFlags"
args1(0).Value = 6144
dispatcher.executeDispatch(doc, ".uno:ExecuteSearch", "", 0, args1())
However createsearchdescriptor will not recognize searchflags=6144
I'm confused because executeSearch will find
args1(0).Name = "SearchItem.SearchString"
args1(0).Value = "Find this"
and
createsearchdescriptor will also find SearchString="Find this"
Can createsearchdescriptor search only selected text?
ExecuteSearch versus createSearchDescriptor
-
- Posts: 18
- Joined: Thu Jan 16, 2014 2:22 am
ExecuteSearch versus createSearchDescriptor
Open Office 3.4.1 on Windows 7
Re: ExecuteSearch versus createSearchDescriptor
Don't waste your time with all this bullshit. It's not worth it. menu:Edit>Find&Replace (Ctrl+F) is the way to go when using this office suite.
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
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Re: ExecuteSearch versus createSearchDescriptor
That's a sorry answer. OO find function is bad enough as it is, any attempt to make it more useable through macros should be encouraged.
@NorthTexasOldMan: try searchflags=2048
@NorthTexasOldMan: try searchflags=2048
OpenOffice 7.1.3.2 on Mac OS X 10.15.7
Re: ExecuteSearch versus createSearchDescriptor
birnbacs - the searchdescriptor in OO doesn't have a searchflags property.
I could be wrong but I think the dispatch helper has to be used for a find in a selection... though you can use compareRegionEnds/starts to go through a search result and see if its in a selection/range
I could be wrong but I think the dispatch helper has to be used for a find in a selection... though you can use compareRegionEnds/starts to go through a search result and see if its in a selection/range
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
Re: ExecuteSearch versus createSearchDescriptor
For a find all in a selection you can try something like this:
Temporarily apply a property to the selection(s) that you don't use... such as charflash... then search for that property and your other attributes, then remove the charflash.
Edit: some small mods
Edit2: simplified, don't seem to need temporary array of sel ranges.
Temporarily apply a property to the selection(s) that you don't use... such as charflash... then search for that property and your other attributes, then remove the charflash.
Code: Select all
sels= thiscomponent.currentcontroller.selection
for i = 0 to sels.count -1
sels(i).charflash= true
next
'insert your find all code here - include the charflash property.
for i = 0 to sels.count -1
sels(i).charflash= false
next
Edit2: simplified, don't seem to need temporary array of sel ranges.
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
Re: ExecuteSearch versus createSearchDescriptor
Slightly more rigorous to find and restore any existing text with charflash:
Edit: oops... added clearing existing charflash if any
Code: Select all
sub FindAllInSelection
Dim SrchAttributes(0) as new com.sun.star.beans.PropertyValue
dim doc,sels,find,flashfind,i as long
doc = thiscomponent
sels= doc.currentcontroller.selection
find = Doc.createSearchDescriptor
SrchAttributes(C).NAME = "CharFlash"
SrchAttributes(C).VALUE = true
Find.SetSearchAttributes(SrchAttributes())
flashfind= doc.findall(find)
if flashfind.count >0 then
for i = 0 to flashfind.count -1
flashfind(i).charflash = false
next
end if
for i = 0 to sels.count -1
sels(i).charflash= true
next
'insert your find all code here - include the charflash property.
for i = 0 to sels.count -1
sels(i).charflash= false
next
if flashfind.count >0 then
for i = 0 to flashfind.count -1
flashfind(i).charflash = true
next
end if
end sub
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
Re: ExecuteSearch versus createSearchDescriptor
1. The original question by NorthTexasOldMan was posted 2014-07-20. The questioners last visit to the forum was 2014-08-02 20:38.birnbacs wrote:That's a sorry answer. OO find function is bad enough as it is, any attempt to make it more useable through macros should be encouraged.
@NorthTexasOldMan: try searchflags=2048
2. OpenOffice (OO) is a name not used by LibreOffice for (assumed) legal reasons. It's used by Apache for their branch of the software. Your Signature is telling you are using a recent version of LibreOffice.
3. With Ctrl+F you may open the FindBar with its limited functionality. To get the dialog for the much more powerful Find&Replace tool, you can use (in LibO) Ctrl+H by default. Using this dialog you get all the available options. No "macros" needed - except for very special reoccurring tasks, probably.
On Windows 10: LibreOffice 25.2.4 and older versions, PortableOpenOffice 4.1.7 and older, StarOffice 5.2
---
Lupp from München
---
Lupp from München