如题,我想首先判定本机是否已经安装Excel,如果安装了,然后得到Excel的版本号,请高手支招,谢了。

解决方案 »

  1.   

    //判断本机是否安装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;
    }
      

  2.   

    在不知道如何取得用[判断本机是否安装Excel文件方法]那边来取得 "Version" 之前也只能这样了
      

  3.   

    看你的office是多少版本的就可以了在桌面右键创建看是否可以创建.xls或者.xlsx的文件 
      

  4.   

    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;
            }