Find out which version of Excel is installed in the .NET Framework

Page creation date :

To get the installed version of Excel, use the Type.GetTypeFromProgID method to get the type of Excel.Application and generate an instance with theActivator.CreateInstance method. Not generating an instance of Excel.Application directly is to avoid being version-dependent by direct lye. This way, you will be able to see the latest version.

You can then reference the Version property from the generated application instance to get the version. The version retrieved is the version that Excel has internally. For example, Excel 2010 is 14.0, and Excel 2013 is 15.0.

Also, to use these classes, you must configure System.Reflection and System.Runtime.InteropServices in using.

/// <summary>
/// インストールされている Excel のバージョンを取得します。
/// </summary>
/// <returns>インストールされている Excel のバージョン。</returns>
public static decimal GetInstallExcelVersion()
{
  // Excelアプリケーションに接続
  var type = Type.GetTypeFromProgID("Excel.Application");
  object application = null;
  try
  {
    application = Activator.CreateInstance(type);

    if (application == null)
    {
      // 未インストールの場合
      return 0;
    }

    // バージョンを取得
    var ver =
        application.GetType().InvokeMember(
        "Version", BindingFlags.GetProperty, null, application, null);

    decimal version;
    if (!decimal.TryParse(ver.ToString(), out version))
    {
      return 0;
    }
    return version;
  }
  finally
  {
    if (application != null)
    {
      Marshal.ReleaseComObject(application);
    }
  }
}

Other sites have similar descriptions, but some sites do not release applications with Marshal.ReleaseComObject. If you forget this, the Excel process will remain, so make sure you release it in finally.