xscript invoke macro of specify file

Creating a macro - Writing a Script - Using the API

xscript invoke macro of specify file

Postby orgoo » Tue May 07, 2013 1:46 pm

Hi All,

I'm using next code to invoke macro function in java class :

Code: Select all   Expand viewCollapse view
     XComponentContext mxRemoteContext = com.sun.star.comp.helper.Bootstrap.bootstrap();
    XMultiComponentFactory mxRemoteServiceManager = mxRemoteContext   .getServiceManager();
   
    Object oMSPFac = mxRemoteServiceManager.createInstanceWithContext("com.sun.star.script.provider.MasterScriptProviderFactory",mxRemoteContext);
    XScriptProviderFactory xScriptProviderFactory = (XScriptProviderFactory) UnoRuntime.queryInterface(XScriptProviderFactory.class, oMSPFac);

    Object oMSP = xScriptProviderFactory.createScriptProvider("");
    XScriptProvider xScriptProvider = (XScriptProvider) UnoRuntime.queryInterface(XScriptProvider.class, oMSP);

    XScript xScript = xScriptProvider.getScript("vnd.sun.star.script:Standard.Module1.fnTest?language=Basic&location=application");

   short[][] aOutParamIndex = new short[1][1];
   Object[][] aOutParam = new Object[1][1];
         
   String[] test= {"1","2","3"};   
         
   xScript.invoke(test, aOutParamIndex, aOutParam);


this code can call the macro correctly, but the macro must be placed in libreoffice installation, e.g. C:\Users\username\AppData\Roaming\LibreOffice\4\user\basic.

how can I call the macro function of specify file? e.g. I want to call one macro function of E:\temp.ods.

Thanks in advance!
LibreOffice 4.0.4.2 on Ubuntu 12.04
orgoo
 
Posts: 71
Joined: Wed Apr 03, 2013 10:26 am

Re: xscript invoke macro of specify file

Postby JulianR » Tue Apr 28, 2020 12:40 pm

If anyone is looking for an answer to such question, then the answer is:
The line containing:
Code: Select all   Expand viewCollapse view
Object oMSP = xScriptProviderFactory.createScriptProvider("");
xScriptProviderFactory.createScriptProvider("") instead of empty string must be provided with object instance of class XComponent, that holds the reference to the document containing the macro. (for example created with XComponentLoader)
And the line containing
Code: Select all   Expand viewCollapse view
XScript xScript = xScriptProvider.getScript("vnd.sun.star.script:Standard.Module1.fnTest?language=Basic&location=application");
last parameter - location should be changed from application to document
Apache OpenOffice 4.1.1 / LibreOffice 5.3 / LibreOffice 6.0 / LibreOffice 6.2 on Windows 7
JulianR
 
Posts: 26
Joined: Mon Mar 12, 2018 9:41 am


Return to Macros and UNO API

Who is online

Users browsing this forum: No registered users and 5 guests