Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / productivity / Office / MS-Excel

How to Check Whether Excel is Installed in the System or Not

7 Nov 2013CPOL 63.8K  
Here we will explore the trick to verify whether Excel is installed in the client's system or not by C#.

Introduction

If you are using <a title="Microsoft.Office.Interop.Excel Namespace" href="http://msdn.microsoft.com/en-us/library/ms262200(v=office.11).aspx">Microsoft.Office.Interop.Excel</a> for Excel related operations in your application, then you must check if Excel is installed in the client machine or not. This tip gives you that trick.

Background

This little piece of code is a result of the research during development of one Windows Utility, which uploads Excel sheets to database.

Using the Code

We will use Type Class and its method Type.GetTypeFromProgID Method (String).

Gets the type associated with the specified program identifier (ProgID), returning null if an error is encountered while loading the Type.

Return Value

Type: System.Type
The type associated with the specified ProgID, if progID is a valid entry in the registry and a type is associated with it; otherwise, null.

For Excel, the ProgID is Excel.Application. So, the below code is used to check whether Excel is installed or not.

C#
Type officeType = Type.GetTypeFromProgID("Excel.Application");

if (officeType == null)
{
    // Excel is not installed.
    // Show message or alert that Excel is not installed.
}
else
{
    // Excel is installed.
    // Continue your work.
}

History

  • 07 November 2013 - First version submitted for approval

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)