【发布时间】:2015-04-23 04:49:19
【问题描述】:
在我的 C# 程序中,我使用的是 Microsoft.Office.Interop.Excel。有了这个,我正在读取和写入数据到 excel 文件。在一台机器上,即使它有 Office 2007,也会看到以下异常,在 GetComponentPath() 方法调用时引发。
未处理的异常: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 框架 4.0 @user3588674
标签: c# asp.net .net c#-4.0 c#-3.0