Ask Your Question

bertrandgajac's profile - activity

2018-09-21 00:35:47 +0200 received badge  Famous Question (source)
2018-09-21 00:35:47 +0200 received badge  Notable Question (source)
2018-05-28 17:05:45 +0200 received badge  Popular Question (source)
2018-05-28 16:41:27 +0200 marked best answer How to call from C# a basic macro defined in a calc document ?

I have written a C# program that opens a LibreOffice calc file, then writes data inside the file and then saves the file. The calc file contains a basic macro called MettreEnPage that is used to define the layout of the data. I want that my C# program calls the basic macro MettreEnPage. The piece of code is the following.

            Object aFuncInst = oServMan.createInstance("com.sun.star.sheet.FunctionAccess");
            unoidl.com.sun.star.sheet.XFunctionAccess xFuncAcc = (unoidl.com.sun.star.sheet.XFunctionAccess)aFuncInst;
            uno.Any[] aArgs = new uno.Any[1];
            aArgs[0] = new uno.Any(0);
            uno.Any aResult = xFuncAcc.callFunction("MettreEnPage", aArgs);

There is an exception when the function xFuncAcc.callFunction is called. The exception gives no information. My questions are the following:

  • is it possible to call a basic macro defined in a calc file from a C# program ?
  • If yes, what is the solution ?

Thank you for your help.

2018-05-28 16:41:27 +0200 received badge  Scholar (source)
2018-05-28 16:41:18 +0200 received badge  Supporter (source)
2018-05-28 16:40:19 +0200 answered a question How to call from C# a basic macro defined in a calc document ?

Thank you Jim K for your answer. It works correctly. I have tried your solution described in Python in your answer and a

2018-05-25 18:04:00 +0200 received badge  Student (source)
2018-05-25 12:11:57 +0200 asked a question How to call from C# a basic macro defined in a calc document ?

How to call from C# a basic macro defined in a calc document ? I have written a C# program that opens a LibreOffice calc