How to check programmatically if MS Excel exists on a computer?

I have an application that requires MS Excel, otherwise it will work. Therefore, I want to check and warn the user in case Excel is not installed on the user machine.

How to do it?

+15
c # excel interop winforms
Aug 19 2018-11-11T00:
source share
5 answers
Type officeType = Type.GetTypeFromProgID("Excel.Application"); if (officeType == null) { //no Excel installed } else { //Excel installed } 
+32
Aug 19 2018-11-11T00:
source share
 const string ASSEMBLY2003 = "Microsoft.Office.Interop.Excel, Version=11.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"; static bool IsAssemblyInstalled(string assembly) { try { s_assemblyExcel = Assembly.Load(assembly); return true; } catch { return false; } } 

this will do the trick, just do it for all versions

and it can be done the same

 RegistryKey key = Registry.ClassesRoot; RegistryKey excelKey = key.OpenSubKey("Excel.Application"); bool excelInstalled = excelKey == null ? false : true; 
+3
Aug 19 2018-11-11T00:
source share

As a quick fix, you can simply catch the exception and implement the correct error handling. Then you can report this to the user.

+2
Aug 19 2018-11-11T00:
source share

This blog describes how to check if Excel is installed through the registry (VB.NET code, but it can be easily converted to C #). In principle, you will check using the HKEY_CLASSES_ROOT\Excel.Application\CurVer .

+2
Aug 19 2018-11-11T00:
source share

This does not answer your specific question, but solves it from an alternative direction ...

Do you really need to install MS Excel, or do you need a computer to just display Excel files? For example, if a user has LibreOffice or another similar application compatible with an Excel file, is this acceptable?

We have an application that opens Excel files and PDF files for the user. We don't care what kind of software they have on their computer to view these files. This is not our concern. We are just a Process.Start(...) file and let the OS take it away from there.

We end the call in the Try/Catch block and offer suggestions for users if this call leads to an error; suggestions, for example, that they may not have Office (Excel), or that they do not have a PDF viewer. In principle, instead of proactively trying to determine if the user computer is in sufficient condition to complete the action, we assume that it is there, but then we handle the situation when it was found more than once.

+2
Aug 19 2018-11-11T00:
source share



All Articles