在我的 MVC 5 应用程序中,我想使用 Microsoft.Office.Interop.Excel
库。我使用 Visual Studio 2013 和 Office 2013。我添加了引用 Microsoft.Excel 15.0 Object Library
并在我的类(class)中添加了 using Excel = Microsoft.Office.Interop.Excel;
当我单击 build
时,它没有显示任何错误并提示 Build Complete
,但是当我运行我的应用程序时,我收到此错误
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: CS1748: Cannot find the interop type that matches the embedded interop type 'Microsoft.Office.Interop.Excel.Application'. Are you missing an assembly reference?
Source Error:
[No relevant source lines]
Source File: Line: 0
它可能是什么?
最佳答案
您有适用于 MS 2010 的程序集,但安装了 Office 2013。程序集不向前兼容。您必须安装与 DLL 相同版本的 office,或者最好使用 OpenXml sdk 之类的东西。
然后看起来缺少一些必要的程序集。您将必须添加对程序集的引用。
找不到与嵌入式互操作类型“”相匹配的互操作类型。您是否缺少程序集引用? 此方法与前面的错误类似,如果一个程序集嵌入了类型信息而另一个程序集没有嵌入类型信息,则会发生此错误。在这种情况下,您有一个程序集 assembly1,它引用了一个嵌入互操作类型设置为 true 的 PIA 程序集。 Assembly1 然后公开来自 PIA 程序集的类型,例如作为方法或属性的返回类型。另一个程序集 assembly2 引用 assembly1 并使用嵌入类型。如果 assembly2 没有引用 PIA 程序集,则会出现错误,因此无法找到嵌入的类型信息。 要解决此问题,您需要将第二个程序集的引用添加到 PIA 程序集并将 Embed Interop Types 属性设置为 true。因此,两个程序集都将引用 PIA 程序集,并嵌入类型信息,并且都可以使用嵌入的类型。
关于c# - 使用 Excel = Microsoft.Office.Interop.Excel 编译错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20198519/