zoukankan      html  css  js  c++  java
  • c# 判断office是否安装 C#判断office版本

    因为程序需要判断office2010版本以上才可以使,网上找了好多检测office版本都不能用,

    参考https://jingyan.baidu.com/article/2c8c281d0844084008252a8f.html

    根据注册表信息检查,代码改进了一下office2007 2010,2013,2016都能检测到

    public void checkOffice()
            {
                bool ifused = false;
                int officeVersion = 0;
    
                RegistryKey rk = Registry.LocalMachine;
                RegistryKey akey07 = rk.OpenSubKey(@"SOFTWAREMicrosoftOffice12.0ExcelInstallRoot");//查询2007
                RegistryKey akey10 = rk.OpenSubKey(@"SOFTWAREMicrosoftOffice14.0ExcelInstallRoot");//查询2010
                RegistryKey akey13 = rk.OpenSubKey(@"SOFTWAREMicrosoftOffice15.0ExcelInstallRoot");//查询2013
                RegistryKey akey16 = rk.OpenSubKey(@"SOFTWAREMicrosoftOffice16.0ExcelInstallRoot");//查询2016
    
                //检查本机是否安装Office2007
                if (akey07 != null)
                {
                    string office07 = akey07.GetValue("Path").ToString();
                    if (File.Exists(office07 + "Excel.exe"))
                    {
                        ifused = true;
                        officeVersion = 2007;
                    }
                }
    
                //检查本机是否安装Office2010
                if (akey10 != null)
                {
                    string office10 = akey10.GetValue("Path").ToString();
                    if (File.Exists(office10 + "Excel.exe"))
                    {
                        ifused = true;
                        officeVersion = 2010;
                    }
                }
    
                //检查本机是否安装Office2013
                if (akey13 != null)
                {
                    string office13 = akey13.GetValue("Path").ToString();
                    if (File.Exists(office13 + "Excel.exe"))
                    {
                        ifused = true;
                        officeVersion = 2013;
                    }
    
                }
    
                //检查本机是否安装Office2016       
                if (akey16 != null)
                {
                    string office16 = akey16.GetValue("Path").ToString();
                    if (File.Exists(office16 + "Excel.exe"))
                    {
                        ifused = true;
                        officeVersion = 2016;
                    }
                }
    
    
                Debug.WriteLine("result:"+ ifused.ToString());
                Debug.WriteLine("office:" + officeVersion.ToString());
            }

    debug调试结果:
    result:True
    office:2016

  • 相关阅读:
    表格文字溢出用省略号代替处理方法
    【Linux】Mysql5.7.12源码编译安装及配置
    【Linux】JDK安装及配置
    [SDOI2017]序列计数
    P1777 帮助_NOI导刊2010提高(03)
    BSGS和EXBSGS
    排列最小值
    三元组[01 Trie计数]
    数学题
    The Preliminary Contest for ICPC Asia Xuzhou 2019 E XKC's basketball team [单调栈上二分]
  • 原文地址:https://www.cnblogs.com/q149072205/p/12448450.html
Copyright © 2011-2022 走看看