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#:
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.
发布评论
评论(2)
不是直接回答您的问题,但在开始加载项开发之前也值得考虑:正如 Reed 所说,使用 VB.Net 开发 Office 加载项将比使用 C# 更容易。
对 Office 对象模型的调用通常会省略几个可选参数。 但是,在 C# 中 - 因为 C# 还没有可选参数 - 您必须指定每个可选参数。 还不够,对于 COM 加载项,您还必须自己处理参数装箱,即您必须首先将其转换为引用类型,而不是传递简单的 bool 或 int。 所有这些都使得代码非常不可读。
例如,在 Word 中打开文档的代码与 C# 中的代码类似:
而在 VB.Net 中打开文档的代码则更容易阅读和编写:(
附加信息:使用 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#:
whereas the same in VB.Net would be much easier to read and write:
(Additional info: With C# 4.0 this will become much simpler using dynamic)
如果您打算使用 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.