Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using C# with OpenOffice through reflection

Tags:

c#

reflection

I'm working on some code to paste into the currently active OpenOffice document directly from C#. I can't include any of the OpenOffice libraries, because we don't want to package them, so we're using reflection to get access to the OpenOffice API.

My question involves using a dispatcher through reflection. I can't figure out the correct parameters to pass to it, giving me a lovely "TargetInvocationException" due to mismatched types.

object objframe = GetProperty<object>(objcontroller, "frame");
if (objframe != null)
{
    object[] paramlist = new object[2] {".uno:Paste", objframe};
    InvokeMethod<object>(objdispatcher, "executeDispatch", paramlist);
}

How can I fix it?

like image 312
Dave Kasper Avatar asked Nov 15 '22 17:11

Dave Kasper


1 Answers

Is it just me or are your parameters the wrong way around? Also, do you have the right number of parameters? I could be missing something though, so sorry if you've already checked this stuff:

The documentation says:

dispatcher.executeDispatch(document, ".uno:Paste", "", 0, Array())

Which would indicate to me that you need to have your parameter list defined as

object[] paramlist = new object[5] {objframe, ".uno:Paste", "", 0, null};
like image 186
lomaxx Avatar answered Dec 10 '22 12:12

lomaxx