我想创建一个Excel程序集的引用并使用此代码:
[Test] public void ExcelTest() { Assembly current = this.GetType().Assembly; Assembly excel = typeof(Microsoft.Office.Interop.Excel.Workbook).Assembly; Assert.AreEqual(current.FullName, excel.FullName); // Why is excel the same as current assembly? } [Test] public void MscorlibTest() { Assembly mscorlib = typeof(string).Assembly; Assert.IsTrue(mscorlib.FullName.StartsWith("mscorlib")); Assembly current = this.GetType().Assembly; Assert.AreNotEqual(mscorlib.FullName,current.FullName); // As expected }
为什么excel和我现在的装配一样?
获得Excel程序集的好方法是什么?
在阅读文档时无法找到我的愚蠢
Excel等通过COM互操作类型到达.它是一个界面,用GUID和东西装饰.使用它时,它使用COM与正在运行的Excel应用程序进行通信.因此,您的引用不是Excel本身,而只是一个瘦COM通信层.
COM互操作类型可以嵌入到您的程序集中,这似乎就是这种情况.您可以将其指定为项目中程序集引用的属性.
例如,请参阅:http://msdn.microsoft.com/en-us/library/dd997297%28v=vs.110%29.aspx或http://msdn.microsoft.com/en-us/library/ee317478. ASPX