Office(尤其是 Outlook)插件

发布于 2024-07-15 23:28:54 字数 1432 浏览 8 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

一个人的旅程 2024-07-22 23:28:55

不是直接回答您的问题,但在开始加载项开发之前也值得考虑:正如 Reed 所说,使用 VB.Net 开发 Office 加载项将比使用 C# 更容易。

对 Office 对象模型的调用通常会省略几个可选参数。 但是,在 C# 中 - 因为 C# 还没有可选参数 - 您必须指定每个可选参数。 还不够,对于 COM 加载项,您还必须自己处理参数装箱,即您必须首先将其转换为引用类型,而不是传递简单的 bool 或 int。 所有这些都使得代码非常不可读。

例如,在 Word 中打开文档的代码与 C# 中的代码类似:

object objTrue = true;
object objFalse = false;
object missing = Type.Missing;
object objInputFile = strInputFile;
Document document = WordApplication.Documents.Open(ref objInputFile, 
    ref objFalse, ref objTrue, ref objFalse, ref missing, ref missing, 
    ref missing, ref missing, ref missing, ref missing, ref missing, 
    ref objFalse, ref missing, ref missing, ref objTrue, ref missing);

而在 VB.Net 中打开文档的代码则更容易阅读和编写:(

Document document = WordApplication.Documents.Open(strInputFile)

附加信息:使用 C# 4.0,使用 动态

Not directly an answer to your question but also worth considering before starting add-in development: As already said by Reed, when developing an Office add-in using VB.Net will make life a lot easier than using C#.

A call into the Office object model typically leaves out several optional parameters. However, in C# - because C# does not (yet) have optional parameters - you will have to specify each and every of the optional parameters. Not enough, for COM add-ins you will also have to take care of boxing the arguments yourself, i.e. instead of passing a simple bool or int you have to convert it to a reference type first. All this makes code quite unreadable.

E.g. the code to open a document in Word would look like that in C#:

object objTrue = true;
object objFalse = false;
object missing = Type.Missing;
object objInputFile = strInputFile;
Document document = WordApplication.Documents.Open(ref objInputFile, 
    ref objFalse, ref objTrue, ref objFalse, ref missing, ref missing, 
    ref missing, ref missing, ref missing, ref missing, ref missing, 
    ref objFalse, ref missing, ref missing, ref objTrue, ref missing);

whereas the same in VB.Net would be much easier to read and write:

Document document = WordApplication.Documents.Open(strInputFile)

(Additional info: With C# 4.0 this will become much simpler using dynamic)

铜锣湾横着走 2024-07-22 23:28:55

如果您打算使用 C# 进行开发,我强烈建议您坚持使用 VSTO。 它有一个更简单的附加开发框架,并且与 C# 完美配合。

采用 COM 路线,尤其是使用 C#,只会增加目前不必要的额外痛苦。

If you are going to be developing in C#, I highly recommend sticking with VSTO. This has a much simpler add-development framework, and works perfectly with C#.

Going the COM route, especially with C#, is just adding extra pain that's unnecessary at this point.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文