How to detect MS Excel installed on the system

July 01, 2013 by Anuraj

.Net .Net 3.0 / 3.5 .Net 4.0

Today I faced an issue, I want to open an excel file from a Windows application; before opening the file, I want to verify that MS Excel installed on the system. I found a solution using registry from MSDN.

Here is the code snippet.

//14.0 is the version of the office installed.
var key = @"SOFTWARE\Microsoft\Office\14.0\Common\InstallRoot\";
var installRoot = Registry.LocalMachine.OpenSubKey(key, false);
if (installRoot != null)
    //This will return the installation folder.
    var installedPath = installRoot.GetValue("Path");

But the problem with the source code is I need to know the office versions, and can identify exactly which versions are installed.

And here is the office version information.

**Office Version****Version Number**
Office 20009.0
Office XP10.0
Office 200311.0
Office 200712.0
Office 201014.0
Office 201315.0

I don’t want to know the version of the excel installed. I just want to open a XLS file created by the application. Later I found another code snippet which will return whether Excel installed or not. Here is the code snippet.

var excelApplication = Type.GetTypeFromProgID("Excel.Application");
if (null == excelApplication)
    //Excel not installed.

Happy Programming

Copyright © 2024 Anuraj. Blog content licensed under the Creative Commons CC BY 2.5 | Unless otherwise stated or granted, code samples licensed under the MIT license. This is a personal blog. The opinions expressed here represent my own and not those of my employer. Powered by Jekyll. Hosted with ❤ by GitHub