Excel interop MissingMethodException在某些系统上
在我的C#程序中,我使用的是Microsoft.Office.Interop.Excel。有了这个,我正在读取&将数据写入excel文件。在一台机器上,即使它具有Office 2007,但在下面的例外情况下,会在GetComponentPath()方法调用时引发。Excel interop MissingMethodException在某些系统上
未处理的异常:System.MissingMethodException:未找到方法:'System.Type System.Runtime.InteropServices.Marshal.GetTypeFromCLSID(System.GUID)'。
这里是我的代码:
public static string GetComponentPath(OfficeComponent _component)
{
string toReturn = string.Empty;
string _key = string.Empty;
try
{
Microsoft.Office.Interop.Excel.Application _excelApp = null;
_excelApp = new Microsoft.Office.Interop.Excel.Application();
if (_excelApp != null)
{
Console.WriteLine("Excel is installed");
}
else
{
Console.WriteLine("Excel not found.");
}
}
catch (Exception ex)
{
Console.WriteLine("Error \n" + ex.ToString());
}
return toReturn;
}
public enum OfficeComponent
{
Word,
Excel,
PowerPoint,
Outlook
}
问题:您已经开发在本地计算机您的应用程序的.NET Framework
heigher版本,并在具有.NET Framework
低版本的远程PC相同。
注意:如果您的应用程序运行在Heigher
版本的.NET Framework
它不会在较低版本上运行。
解决方案:您需要将其定位到.NET Framework
远程PC上的远程PC上可以运行的较低版本。
第1步:右击project
- 选择properties
步骤2:从.NET Framework x.x
的Target Framework
改为.NET Framework x.y
。
注意:其中x.x
更高,x.y
是远程PC或更低版本上可用的较低版本。
我开发了我的应用程序在.net framework 4.0中,并且有必要让其他机器也应该安装4.0,否则应用程序将无法运行。但在其他系统应用程序正在运行,但excel部分不起作用。 –
您是否安装了ms office ... – sheshadri
办公室2007已经安装在系统中。 –
您正在使用哪种框架? – sheshadri
我正在使用.net框架4.0 @ user3588674 –