通过反射在 OpenOffice 中使用 C#

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10531/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-07-31 17:36:01  来源:igfitidea点击:

Using C# with OpenOffice through reflection

提问by Dave Kasper

I'm working on some code to paste into the currently active OpenOfficedocument 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.

我正在编写一些代码以直接从 C#粘贴到当前活动的OpenOffice文档中。我不能包含任何 OpenOffice 库,因为我们不想打包它们,所以我们使用反射来访问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.

我的问题涉及通过反射使用调度程序。我无法弄清楚要传递给它的正确参数,由于类型不匹配,给了我一个可爱的“TargetInvocationException”。

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?

我该如何解决?

回答by lomaxx

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};