Microsoft Office 版本检测器






4.55/5 (9投票s)
以编程方式确定 Microsoft Office 应用程序的版本
引言
OfficeVersion
是一个简单的 C++ 类,用于以编程方式检测流行的 Microsoft Office 应用程序的存在和版本。
为什么要这样做? 也许您的应用程序中有一个 Excel 自动化功能,您希望启用/禁用它? 也许您的应用程序使用与 Microsoft Office 应用程序之一类似的视觉风格,并且您希望更改您的界面以匹配用户安装的 Office 的特定版本。
应用程序和版本
将检测以下 Microsoft Office 应用程序
- 单词
- Excel
- Outlook(展望)
- 访问
- PowerPoint
- Office 95
- Office 97
- Office 2000
- Office XP
- Office 2003
- Office 2007
多个版本?
如果安装了多个版本的应用程序,则检测到的版本是“注册”的版本(即,双击文件时将打开该文件的应用程序版本)。
用法
- 将“OfficeVersion.h”添加到您的项目中(只需要这个文件)。 目前,代码使用 MFC/ATL
CString
类,但可以轻松更改为另一个 C++ 字符串类。#include "OfficeVersion.h"
- 以下示例代码检查 Excel 的版本(注意:文本的粗体部分只是为了突出显示代码的特定部分)。
OfficeVersion::eOfficeVersion excelVersion = OfficeVersion::GetApplicationVersion(OfficeVersion::eOfficeApp_Excel); // excelVersion will now be one of the following values: // // OfficeVersion::eOfficeVersion_Unknown, // not found, or an error occurred // OfficeVersion::eOfficeVersion_95 // OfficeVersion::eOfficeVersion_97 // OfficeVersion::eOfficeVersion_2000 // OfficeVersion::eOfficeVersion_XP // OfficeVersion::eOfficeVersion_2003 // OfficeVersion::eOfficeVersion_2007
- 以下示例代码检查“Office”的版本(注意:文本的粗体部分只是为了突出显示代码的特定部分)。
OfficeVersion::eOfficeVersion officeVersion = OfficeVersion::GetOfficeVersion(); // office Version will now be one of the following values: // // OfficeVersion::eOfficeVersion_Unknown, // not found, or an error occurred // OfficeVersion::eOfficeVersion_95 // OfficeVersion::eOfficeVersion_97 // OfficeVersion::eOfficeVersion_2000 // OfficeVersion::eOfficeVersion_XP // OfficeVersion::eOfficeVersion_2003 // OfficeVersion::eOfficeVersion_2007
算法说明
由于“Office”是一系列应用程序,而不是单个应用程序,因此确定“Office”的存在和版本的算法是遍历 Office 应用程序集,并使用找到的第一个应用程序。 搜索按应用程序的(近似)流行程度进行(即,Word 然后 Excel 然后 Outlook 然后 Access 然后 PowerPoint)。
它是如何工作的?
该代码基于过时的 Microsoft 知识库文章 Q247985(知识库文章中的代码不适用于 Office 2003 或 2007)。 该代码查找一个特定的注册表键,该键包含每个应用程序的版本(例如,Excel 的 HKEY_CLASSES_ROOT/Excel.Application/CurVer),其中版本编码在一个字符串中(例如,我的计算机上的“Excel.Application.11
”)。 然后将内部 Microsoft 版本号(即,“Excel.Application.11
”末尾的“11
”)映射到外部“营销”名称,您会更熟悉该名称(例如,内部版本“11”更常见地称为“Office 2003”)。
历史
- 2006-12-04:版本 1.0 - 初始发布。