如何用C#得到本机上Excel的版本呢? 如题,我想首先判定本机是否已经安装Excel,如果安装了,然后得到Excel的版本号,请高手支招,谢了。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 //判断本机是否安装Excel文件方法private bool codeboolisExcelInstalled(){ Type type = Type.GetTypeFromProgID("Excel.Application"); return type != null;}/// <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\\"); //检查本机是否安装Office2003 if (akey != null) { string file03 = akey.GetValue("Path").ToString(); if (File.Exists(file03 + "Excel.exe")) { ifused = true; } } //检查本机是否安装Office2007 if (akeytwo != null) { string file07 = akeytwo.GetValue("Path").ToString(); if (File.Exists(file07 + "Excel.exe")) { ifused = true; } } return ifused;} 在不知道如何取得用[判断本机是否安装Excel文件方法]那边来取得 "Version" 之前也只能这样了 看你的office是多少版本的就可以了在桌面右键创建看是否可以创建.xls或者.xlsx的文件 public static double JongCheckExcelVer() { Type objExcelType = Type.GetTypeFromProgID("Excel.Application"); if (objExcelType == null) { return 0; } object objApp = Activator.CreateInstance(objExcelType); if (objApp == null) { return 0; } object objVer = objApp.GetType().InvokeMember("Version", BindingFlags.GetProperty, null, objApp, null); double iVer = Convert.ToDouble(objVer.ToString()); objVer = null; objApp = null; objExcelType = null; GC.Collect(); return iVer; } public static String JongGetExcelVerStr() { String s1; double excelver; excelver = JongCheckExcelVer();// ExistsExcelRegedit(); s1 = " Office "; if (excelver == 0) { MessageBox.Show("無法識別Excel的版本", "錯誤", MessageBoxButtons.OK, MessageBoxIcon.Information); s1 = "無法識別 office 版本"; } else if (excelver >= 14) s1 += "2010或以上"; else if (excelver >= 12) s1 += "2007"; else if (excelver >= 11) s1 += "2003"; else if (excelver >= 10) s1 += "XP"; else if (excelver >= 9) s1 += "2000"; else if (excelver >= 8) s1 += "97"; else if (excelver >= 7) s1 += "95"; return s1; } flowLayoutPanel问题 多线程传递参数的问题 真心求救.急急..... c#的winform 中的问题 控件和Page的Init、 load、PreRender事件顺序疑惑! 刚开始使用2005,这个可执行文件VSHOST.exe 是干什么用的 C#调用其他线程的控键做为控键的父控键 怎么让某个TabPage一直能显示? 请介绍一下有关SVG的情况,以及与C#相关的编程网站 封装文件格式与文件格式 能不能把VB代码转成.net/C#的类? 关于numericUpDown和comboBox初值问题,跪求~~~
private bool codeboolisExcelInstalled()
{
Type type = Type.GetTypeFromProgID("Excel.Application");
return type != null;
}/// <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\\");
//检查本机是否安装Office2003
if (akey != null)
{
string file03 = akey.GetValue("Path").ToString();
if (File.Exists(file03 + "Excel.exe"))
{
ifused = true;
}
}
//检查本机是否安装Office2007
if (akeytwo != null)
{
string file07 = akeytwo.GetValue("Path").ToString();
if (File.Exists(file07 + "Excel.exe"))
{
ifused = true;
}
}
return ifused;
}
{
Type objExcelType = Type.GetTypeFromProgID("Excel.Application");
if (objExcelType == null)
{
return 0;
}
object objApp = Activator.CreateInstance(objExcelType);
if (objApp == null)
{
return 0;
}
object objVer = objApp.GetType().InvokeMember("Version", BindingFlags.GetProperty, null, objApp, null);
double iVer = Convert.ToDouble(objVer.ToString());
objVer = null;
objApp = null;
objExcelType = null;
GC.Collect();
return iVer;
} public static String JongGetExcelVerStr()
{
String s1;
double excelver;
excelver = JongCheckExcelVer();// ExistsExcelRegedit();
s1 = " Office ";
if (excelver == 0)
{
MessageBox.Show("無法識別Excel的版本", "錯誤", MessageBoxButtons.OK, MessageBoxIcon.Information);
s1 = "無法識別 office 版本";
}
else if (excelver >= 14) s1 += "2010或以上";
else if (excelver >= 12) s1 += "2007";
else if (excelver >= 11) s1 += "2003";
else if (excelver >= 10) s1 += "XP";
else if (excelver >= 9) s1 += "2000";
else if (excelver >= 8) s1 += "97";
else if (excelver >= 7) s1 += "95"; return s1;
}