Code: Select all
REM ***** BASIC *****
sub FindReplaceStringInUpLines(n as Integer,find as String,replace as String)
rem ----------------------------------------------------------------------
rem define variables
dim document as object
dim dispatcher as object
rem ----------------------------------------------------------------------
rem get access to the document
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
rem ----------------------------------------------------------------------
dim args1(1) as new com.sun.star.beans.PropertyValue
args1(0).Name = "Count"
args1(0).Value = n
args1(1).Name = "Select"
args1(1).Value = true
dispatcher.executeDispatch(document, ".uno:GoUp", "", 0, args1())
rem ----------------------------------------------------------------------
dim args6(4) as new com.sun.star.beans.PropertyValue
args6(0).Name = "SearchItem.SearchFlags"
args6(0).Value = 71680
args6(1).Name = "SearchItem.SearchString"
args6(1).Value = find
args6(2).Name = "SearchItem.ReplaceString"
args6(2).Value = replace
args6(3).Name = "SearchItem.Command"
args6(3).Value = 3
args6(4).Name = "Quiet"
args6(4).Value = false
dispatcher.executeDispatch(document, ".uno:ExecuteSearch", "", 0, args6())
end sub
Code: Select all
public void findReplaceStringInUpLines(XTextDocument xTextDocument,XTextViewCursor xTextViewCursor,XParagraphCursor xParagraphCursor,String find,String replace,int N){
xTextViewCursor.gotoRange(xParagraphCursor.getEnd(), false);
TextDocument.executeBasicScript(xTextDocument,"Standard.Module2.FindReplaceStringInUpLines",new Object[]{N,find,replace});
}
public static void executeBasicScript(XTextDocument xTextDocument,String scriptPath,Object[] args) {
XScriptProviderSupplier xScriptProviderSupplier = UnoRuntime.queryInterface(XScriptProviderSupplier.class, xTextDocument);
XScriptProvider xScriptProvider = xScriptProviderSupplier.getScriptProvider();
try {
XScript macro = xScriptProvider.getScript("vnd.sun.star.script:" + scriptPath + "?language=Basic&location=application");
macro.invoke(args,new short[1][1],new Object[1][1]);
} catch (
ScriptFrameworkErrorException | WrappedTargetException e) {
e.printStackTrace();
}
}
Title Edited. A descriptive title for posts helps others who are searching for solutions and increases the chances of a reply (Hagar, Moderator).
Was: Documents opened in hidden mode do not support the execution of UNO Basic scripts, do they?