com 互操作:如何从 Excel 或 Access 使用 C#
我在网上看到很多关于 VSTO 和从 c# 自动化 excel 的内容,但很少有人开始连接 c# 程序集以使其在 Excel 中可见。
有人能给我一些非常基本的信息来解释如何创建 COM 接口、GUIDS、ComVisible 等吗?
I see plenty on the web about VSTO and automating excel from c#, but very little to get started on wiring up a c# assembly to make it visible from Excel.
Can someone point me to some very basic info explaining how to create a COM interface, GUIDS, ComVisible etc?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
基本上,您需要做的就是
另外,请确保在程序集版本信息对话框中为应用程序名称和描述添加描述性名称(它们稍后用于选择 COM 类) 。
[1] 在类定义之前添加的代码块:
之后您应该能够像任何其他普通 COM 类一样使用该类。
编辑
应该指出的是,我没有使用 Excel 和 C# COM 类的经验 - 我正在将 C# 与 Microsoft Navision 一起使用,它按照我上面描述的方式工作得很好。
Basically all you need to do is
regasm.exe
tool found in the .NET 2 installation folderAlso, make sure to add a descriptive name to both application name and description in the Assembly version information dialog (they are later used to pick the COM classes).
[1] Block of code to add before class definition:
After that you should be able to use the class like any other normal COM class.
EDIT
It should be noted that I do not have experience with Excel and C# COM classes - I'm using C# together with Microsoft Navision, which works great the way I described above.
有很多书可能会帮助您前进。 Wrox 的“Pro C# 2008”对此有一个很好的章节。
另外,这里有一个 MSDN 博客 有关 COM 对 Excel 可见的文章。
There are many books out there that might get you going. "Pro C# 2008" from Wrox has a great chapter on this.
Also, here is a MSDN blog article about COM Visible to Excel.
使用 ExcelDNA。它允许您在 .Net 中编写不需要注册的 XLL。它也是开源的并且得到了很好的社区支持。
Rather than go down the COM route, it is considerably easier (and less of an install issue) to use something like ExcelDNA. It allow you to write XLLs in .Net that don't require registering. It is also open-source and very well community supported.