Office(尤其是Outlook)加载项 [英] Office (esp. Outlook) addins

查看:378
本文介绍了Office(尤其是Outlook)加载项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们要开发用于Outlook,Word和Excel的插件.到目前为止,我知道两种解决方案.一种用于共享加载项(基于COM),另一种用于构建基于VSTO的加载项. 由于我是新来的,哪个是更好的选择? (或者,如果有第三种方法,请告诉我)我们的目标是Office 2003和2007.而且我更喜欢用C#开发此插件.

We want to develop addins for outlook, word and excel. As of now I am aware of 2 types of solutions. One to go for Shared Add-in (COM based) and other to build VSTO based Add-in. As I am new to this, which would be the better option? (Or if there is 3rd way,please let me know) We are targeting Office 2003 and 2007 both. And I would prefer developing this addins in C#.

推荐答案

不是直接回答您的问题,而是在开始进行外接程序开发之前值得考虑的问题:正如Reed所说,在使用VB开发Office外接程序时.Net将使生活比使用C#简单得多.

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#.

对Office对象模型的调用通常会遗漏几个可选参数.但是,在C#中-由于C#还没有可选参数-您将必须指定每个可选参数.还不够,对于COM加载项,您还必须自己对参数进行装箱操作,即代替传递简单的bool或int,您必须首先将其转换为引用类型.所有这些使代码非常难以阅读.

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.

例如在Word中打开文档的代码看起来像在C#中一样:

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

而VB.Net中的相同内容更容易读写:

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

Document document = WordApplication.Documents.Open(strInputFile)

(其他信息:对于C#4.0,使用

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

这篇关于Office(尤其是Outlook)加载项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆