当前位置: 编程技术>.net/c#/asp.net
验证本机的excel版本的C#代码
来源: 互联网 发布时间:2014-10-14
本文导语: 代码如下: /// /// 安装的excel的版本,0为没有安装,大于1说明安装了多个. /// /// public static List ExcelVersion() { List list = new List(); List lisemp = new List(); List listvison = new List(); RegistryKey rk = Registry.LocalMachine; RegistryKey akey = rk.OpenSubKey(@"SOF...
代码如下:
///
/// 安装的excel的版本,0为没有安装,大于1说明安装了多个.
///
///
public static List ExcelVersion()
{
List list = new List();
List lisemp = new List();
List listvison = new List();
RegistryKey rk = Registry.LocalMachine;
RegistryKey akey = rk.OpenSubKey(@"SOFTWARE\Microsoft\Office");
RegistryKey csk;
string str;
Hashtable hash = new Hashtable();
string[] ss = akey.GetSubKeyNames();
foreach (string s in ss)
{
string strem = @"SOFTWARE\Microsoft\Office" + @"\" + 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;
}