如何以编程方式检查PC上是否存在MS Excel?

Chr*_*pas 19 c# excel interop winforms

我有一个需要MS Excel运行的应用程序,否则崩溃.所以我想检查并警告用户以防用户机器上没有安装Excel.

我该怎么做呢?

Ale*_*ger 37

Type officeType = Type.GetTypeFromProgID("Excel.Application");
if (officeType == null)
{
     //no Excel installed
}
else
{
     //Excel installed
}
Run Code Online (Sandbox Code Playgroud)