Page 1 of 1
[solved] Open a calc document with macro ACTIVATED
Posted: Thu May 10, 2012 11:32 am
by MarcoG
Ciao
I open a calc document in C# in this way:
Code: Select all
XComponentContext oStrap = uno.util.Bootstrap.bootstrap();
XMultiServiceFactory oServMan = (XMultiServiceFactory)oStrap.getServiceManager();
XComponentLoader oDesk = (XComponentLoader)oServMan.createInstance("com.sun.star.frame.Desktop");
string fileName = textBox1.Text;
string fileNameUrl = "file:///" + fileName.Replace("\\", "/");
PropertyValue[] propVals = new PropertyValue[0];
XComponent oDoc = oDesk.loadComponentFromURL(fileNameUrl, "_default", 0, propVals);
XSpreadsheets oSheets = ((XSpreadsheetDocument)oDoc).getSheets();
The file has some macro written in BASIC and linked to a button.
The macro doesn't work when I press the button, nothing happens. I can't run any macro.
May be is due to the way I've opened the file. Have you got any tip?
Grazie
Marco
Re: Open a calc document with macro ACTIVATED
Posted: Thu May 10, 2012 12:08 pm
by Villeroy
Re: Open a calc document with macro ACTIVATED
Posted: Thu May 10, 2012 3:14 pm
by MarcoG
Thanks.
I've done in C#:
Code: Select all
PropertyValue[] propVals = new PropertyValue[1];
propVals[0].Name = "MacroExecutionMode";
propVals[0].Value = unoidl.com.sun.star.document.MacroExecMode.ALWAYS_EXECUTE;
but the third lines give me an error.
propvals[0].value wants a uno.any type and the "unoidl.com.sun.star.document.MacroExecMode.ALWAYS_EXECUTE" is a short...
If you want to give me another tip, thanks a lot!
ciao
Marco
Re: Open a calc document with macro ACTIVATED
Posted: Thu May 10, 2012 3:47 pm
by karolus
Re: Open a calc document with macro ACTIVATED
Posted: Thu May 10, 2012 4:04 pm
by MarcoG
thanks, but it doesn't work. 2 is "int" and C# wants "uno.any".
I can't understand how to convert a "short" to a "uno.any" type.
I think this is the problem.
At pag. 76 of Developer's guide is written "If you need to set the value of such a PropertyValue struct, you must assign an any type... how this is done depends on your language"
ciao
Re: Open a calc document with macro ACTIVATED
Posted: Thu May 10, 2012 5:30 pm
by Charlie Young
MarcoG wrote:
thanks, but it doesn't work. 2 is "int" and C# wants "uno.any".
I can't understand why C# wants an "uno.any" type and not a "short".
ciao
I don't know how it works in c#, but in c++, you assign various types to an Any using an overloaded shift left assignment.
Code: Select all
propVals[0].Value <<= (sal_Int16) com::sun::star::document::MacroExecMode::ALWAYS_EXECUTE_NO_WARN;
Note also the cast from short to sal_int16. Some such may also be necessary in c#.
Re: Open a calc document with macro ACTIVATED
Posted: Thu May 10, 2012 6:25 pm
by MarcoG
Charlie Young wrote:MarcoG wrote:karolus wrote:Hi
I don't know how it works in c#, but in c++, you assign various types to an Any using an overloaded shift left assignment.
Code: Select all
propVals[0].Value <<= (sal_Int16) com::sun::star::document::MacroExecMode::ALWAYS_EXECUTE_NO_WARN;
Note also the cast from short to sal_int16. Some such may also be necessary in c#.
thanks a lot, I still look for a solution in C#. Tips?

Re: Open a calc document with macro ACTIVATED
Posted: Thu May 10, 2012 7:00 pm
by Charlie Young
I'm groping in the dark here, does this work?
Code: Select all
uno.Any a = new uno.Any(4);
propVals[0].Value = a;
Note that
com::sun:

:document::MacroExecMode::ALWAYS_EXECUTE_NO_WARN = 4
Re: Open a calc document with macro ACTIVATED
Posted: Fri May 11, 2012 9:59 am
by MarcoG
Ciao e thanks for your help!
I've written:
Code: Select all
PropertyValue[] propVals = new PropertyValue[1];
propVals[0] = new PropertyValue();
propVals[0].Name = "MacroExecutionMode";
propVals[0].Value = new uno.Any(4); // (unoidl.com.sun.star.document.MacroExecMode.ALWAYS_EXECUTE_NO_WARN);
XComponent oDoc = oDesk.loadComponentFromURL(fileNameUrl, "_default", 0, propVals);
XSpreadsheets oSheets = ((XSpreadsheetDocument)oDoc).getSheets();
There are no errors but I can't run a macro in the opened file yet. I don't know why...
MArco
Re: Open a calc document with macro ACTIVATED
Posted: Fri May 11, 2012 10:05 am
by MarcoG
Now it works!!!!
"4" has to be short!
Code: Select all
propVals[0].Value = new uno.Any((short)4);
Thanks a lot!
MArco