我有一个应用程序需要MS Excel才能运行,否则它就会崩溃。因此,我想检查并警告用户,以防用户的计算机上没有安装Excel。
我该怎么做呢?
发布于 2011-08-19 22:45:37
Type officeType = Type.GetTypeFromProgID("Excel.Application");
if (officeType == null)
{
//no Excel installed
}
else
{
//Excel installed
}
发布于 2011-08-19 22:41:20
作为一种快速修复方法,您可以捕获异常并实现适当的错误处理。然后,您可以在那里通知用户。
发布于 2011-08-19 22:42:44
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;
}
}
这将会起作用,只需对所有版本都这样做
它也可以像这样做
RegistryKey key = Registry.ClassesRoot;
RegistryKey excelKey = key.OpenSubKey("Excel.Application");
bool excelInstalled = excelKey == null ? false : true;
https://stackoverflow.com/questions/7123196
复制相似问题