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(@"SOFTWARE\Microsoft\Office\12.0\Excel\InstallRoot\");//查询2007 RegistryKey akey10 = rk.OpenSubKey(@"SOFTWARE\Microsoft\Office\14.0\Excel\InstallRoot\");//查询2010 RegistryKey akey13 = rk.OpenSubKey(@"SOFTWARE\Microsoft\Office\15.0\Excel\InstallRoot\");//查询2013 RegistryKey akey16 = rk.OpenSubKey(@"SOFTWARE\Microsoft\Office\16.0\Excel\InstallRoot\");//查询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
欢迎加入JAVA技术交流QQ群:179945282
欢迎加入ASP.NET(C#)交流QQ群:17534377
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!
· 周边上新:园子的第一款马克杯温暖上架