【问题标题】:Excel interop MissingMethodException on some systems某些系统上的 Excel 互操作 MissingMethodException
【发布时间】: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


【解决方案1】:

问题:您已经在本地计算机上使用更高版本的.NET Framework 开发了您的应用程序,并在具有更低版本.NET Framework 的远程电脑上运行相同的应用程序。

注意:如果您的应用程序目标是在 Heigher 版本的 .NET Framework 上运行,则它不会在较低版本上运行。

解决方案:您需要将其定位到远程 PC 上可用的 .NET Framework 较低版本才能在远程 PC 上运行。

第一步:右击project - 选择properties

第 2 步:将 Target Framework.NET Framework x.x 更改为 .NET Framework x.y

注意:x.x 更高,x.y 是远程电脑上可用的较低版本或任何较低版本。

【讨论】:

  • 我在.net framework 4.0中开发了我的应用程序,其他机器也必须安装4.0,否则应用程序将无法运行。但在其他系统应用程序正在运行但 excel 部分无法正常工作。
  • 也许这个链接会对你有所帮助..csharp.net-informations.com/excel/csharp-excel-tutorial.htm
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-10-10
  • 1970-01-01
  • 2012-09-11
  • 2015-03-10
  • 2012-01-09
相关资源
最近更新 更多