1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > C# 判断本机是否安装Excel及多版本安装?获取Excel进程信息和打开Excel应用软件

C# 判断本机是否安装Excel及多版本安装?获取Excel进程信息和打开Excel应用软件

时间:2021-02-10 21:35:39

相关推荐

C# 判断本机是否安装Excel及多版本安装?获取Excel进程信息和打开Excel应用软件

/yebihaigsino/blog/item/36e4ea6f864743d281cb4ad9.html

/devzhao/blog/item/3f527e435e91de149313c6b7.html

方法一:

异常判断法(根据返回结果形式)

// 使用地方

private void buttonOk_Click(object sender, EventArgs e)

{

if (codeboolisExcelInstalled())

{

MessageBox.Show("本机已安装Excel文件");

}

else

{

MessageBox.Show("当前系统没有发现可执行的Excel文件, 如需使用Excel功能请先安装office ", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);

}

}

//判断本机是否安装Excel文件方法

private bool codeboolisExcelInstalled()

{

Type type = Type.GetTypeFromProgID("Excel.Application");

return type != null;

}

====================================================================

方法二:

注册表检查发

判断注册表里有没有SOFTWARE\\Microsoft\\Office\\12.0\\Word\\InstallRoot\\Excel.exe 其中12.0 11.0需要同时判断,因为11.0是office 12.0是office

// 使用地方

private void buttonOk_Click(object sender, EventArgs e)

{

if (ExistsRegedit())

{

MessageBox.Show("本机已安装Excel文件");

}

else

{

MessageBox.Show("当前系统没有发现可执行的Excel文件, 如需使用Excel功能请先安装office ", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);

}

}

/// <summary>

/// Self_Variable:查询注册表某个键值是否存在

/// </summary>

/// <returns></returns>

public bool ExistsRegedit()

{

bool ifused = false;

RegistryKey rk = Registry.LocalMachine;

RegistryKey akey = rk.OpenSubKey(@"SOFTWARE\\Microsoft\\Office\\11.0\\Word\\InstallRoot\\");

RegistryKey akeytwo = rk.OpenSubKey(@"SOFTWARE\\Microsoft\\Office\\12.0\\Word\\InstallRoot\\");

//检查本机是否安装Office

if (akey != null)

{

string file03 = akey.GetValue("Path").ToString();

if (File.Exists(file03 + "Excel.exe"))

{

ifused = true;

}

}

//检查本机是否安装Office

if (akeytwo != null)

{

string file07 = akeytwo.GetValue("Path").ToString();

if (File.Exists(file07 + "Excel.exe"))

{

ifused = true;

}

}

return ifused;

}

=======================================

string strInstallPath = file03 /file07 + "Excel.exe";

//获取Excel进程信息

System.Diagnostics.ProcessStartInfo psInfo = new System.Diagnostics.ProcessStartInfo(strInstallPath);

//运行Excel

System.Diagnostics.Process.Start(strInstallPath);

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。