以下代码可以验证本机已安装的excel版本,返回结果为0表示没有安装,大于1表示已安装多个。
有需要的朋友,不妨参考下。
/// <summary>
/// 验证excel版本,0 未安装,大于1 安装多个.
/// </summary>
/// <returns></returns>
public static List<string> ExcelVersion()
{
List<string> list = new List<string>();
List<string> lisemp = new List<string>();
List<string> listvison = new List<string>();
RegistryKey rk = Registry.LocalMachine;
RegistryKey akey = rk.OpenSubKey(@"SOFTWAREMicrosoftOffice");
RegistryKey csk;
string str;
Hashtable hash = new Hashtable();
string[] ss = akey.GetSubKeyNames();
foreach (string s in ss)
{
string strem = @"SOFTWAREMicrosoftOffice" + @"" + s;
csk = rk.OpenSubKey(strem);
string[] csd = csk.GetSubKeyNames();
foreach (string sk in csd)
{
if (sk == "Excel")
{
str = strem + @"" + "Excel";
list.Add(str);
lisemp.Add(s);
}
}
}
if (list != null)
{
for (int index = 0; index < list.Count; index++)
{
list[index] = list[index] + @"InstallRoot";
RegistryKey f = rk.OpenSubKey(list[index]);
if (f != null)
{
listvison.Add(lisemp[index]);
}
}
}
return listvison;
}