[solved] Open a calc document with macro ACTIVATED

Java, C++, C#, Delphi, ??? - Using the UNO bridges

[solved] Open a calc document with macro ACTIVATED

Postby MarcoG » Thu May 10, 2012 11:32 am

Ciao

I open a calc document in C# in this way:
Code: Select all   Expand viewCollapse view
  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
Last edited by RoryOF on Fri May 11, 2012 10:13 am, edited 2 times in total.
Reason: Added green tick [RoryOF, Moderator]
LibreOffice 3.5.2 - Windows Vista SP2
MarcoG
 
Posts: 22
Joined: Thu Apr 12, 2012 5:08 pm
Location: Italia

Re: Open a calc document with macro ACTIVATED

Postby Villeroy » Thu May 10, 2012 12:08 pm

Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04, no OpenOffice, LibreOffice 6.4
User avatar
Villeroy
Volunteer
 
Posts: 28544
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Open a calc document with macro ACTIVATED

Postby MarcoG » Thu May 10, 2012 3:14 pm

Villeroy wrote:http://www.openoffice.org/api/docs/common/ref/com/sun/star/document/MediaDescriptor.html#MacroExecutionMode


Thanks.

I've done in C#:
Code: Select all   Expand viewCollapse view
  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
LibreOffice 3.5.2 - Windows Vista SP2
MarcoG
 
Posts: 22
Joined: Thu Apr 12, 2012 5:08 pm
Location: Italia

Re: Open a calc document with macro ACTIVATED

Postby karolus » Thu May 10, 2012 3:47 pm

AOO4, Libreoffice - 5.1 … 5.3.2.2 on Linux Mint17
User avatar
karolus
Volunteer
 
Posts: 852
Joined: Sat Jul 02, 2011 9:47 am

Re: Open a calc document with macro ACTIVATED

Postby MarcoG » Thu May 10, 2012 4:04 pm



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
Last edited by MarcoG on Thu May 10, 2012 5:31 pm, edited 1 time in total.
LibreOffice 3.5.2 - Windows Vista SP2
MarcoG
 
Posts: 22
Joined: Thu Apr 12, 2012 5:08 pm
Location: Italia

Re: Open a calc document with macro ACTIVATED

Postby Charlie Young » Thu May 10, 2012 5:30 pm

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   Expand viewCollapse view
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#.
Apache OpenOffice 4.1.1
Windows XP
User avatar
Charlie Young
Volunteer
 
Posts: 1559
Joined: Fri May 14, 2010 1:07 am

Re: Open a calc document with macro ACTIVATED

Postby MarcoG » Thu May 10, 2012 6:25 pm

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   Expand viewCollapse view
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? :?
LibreOffice 3.5.2 - Windows Vista SP2
MarcoG
 
Posts: 22
Joined: Thu Apr 12, 2012 5:08 pm
Location: Italia

Re: Open a calc document with macro ACTIVATED

Postby Charlie Young » Thu May 10, 2012 7:00 pm

I'm groping in the dark here, does this work?

Code: Select all   Expand viewCollapse view
uno.Any a = new uno.Any(4);
propVals[0].Value = a;


Note that

com::sun::star::document::MacroExecMode::ALWAYS_EXECUTE_NO_WARN = 4
Apache OpenOffice 4.1.1
Windows XP
User avatar
Charlie Young
Volunteer
 
Posts: 1559
Joined: Fri May 14, 2010 1:07 am

Re: Open a calc document with macro ACTIVATED

Postby MarcoG » Fri May 11, 2012 9:59 am

Ciao e thanks for your help!

I've written:
Code: Select all   Expand viewCollapse view
            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
LibreOffice 3.5.2 - Windows Vista SP2
MarcoG
 
Posts: 22
Joined: Thu Apr 12, 2012 5:08 pm
Location: Italia

Re: Open a calc document with macro ACTIVATED

Postby MarcoG » Fri May 11, 2012 10:05 am

Now it works!!!!

"4" has to be short!
Code: Select all   Expand viewCollapse view
propVals[0].Value = new uno.Any((short)4);


Thanks a lot!
MArco
LibreOffice 3.5.2 - Windows Vista SP2
MarcoG
 
Posts: 22
Joined: Thu Apr 12, 2012 5:08 pm
Location: Italia


Return to External Programs

Who is online

Users browsing this forum: No registered users and 1 guest