[英]com interop: how to consume c# from Excel or Access
I see plenty on the web about VSTO and automating excel from c#, but very little to get started on wiring up ac# assembly to make it visible from Excel. 我在网上看到了很多有关VSTO和从c#自动化excel的信息,但很少有关于连接ac#程序集以使其在Excel中可见的入门。
Can someone point me to some very basic info explaining how to create a COM interface, GUIDS, ComVisible etc? 有人可以指出一些非常基本的信息来解释如何创建COM接口,GUIDS,ComVisible等吗?
Basically all you need to do is 基本上,您需要做的就是
regasm.exe
tool found in the .NET 2 installation folder regasm.exe
工具注册DLL Also, 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). 另外,请确保在“程序集版本信息”对话框中为应用程序名称和描述添加描述性名称(它们以后将用于选择COM类)。
[1] Block of code to add before class definition: [1]在类定义之前添加的代码块:
[ClassInterface(ClassInterfaceType.AutoDual)]
[ProgId("SomeNameHere")]
[ComVisible(true)]
[Guid("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx")]
After that you should be able to use the class like any other normal COM class. 之后,您应该能够像使用其他任何普通COM类一样使用该类。
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. 应该注意的是,我没有使用Excel和C#COM类的经验-我将C#与Microsoft Navision一起使用,这与我上面描述的方式非常有效。
Rather than go down the COM route, it is considerably easier (and less of an install issue) to use something like ExcelDNA . 与其沿用COM路由,不如使用诸如ExcelDNA之类的东西要容易得多(并且不会造成安装问题)。 It allow you to write XLLs in .Net that don't require registering.
它允许您在.Net中编写不需要注册的XLL。 It is also open-source and very well community supported.
它也是开源的,并且得到了社区的很好支持。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.