检测本机Office(excel/word)版本

本文介绍了一个函数用于检测本地Office应用程序的版本,支持Word和Excel。它通过读取注册表信息来确定Office版本,并能判断其是否为2003版、2007版或其他更高版本。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

//----------------公共功能库-----------------*/

#ifndef     FUNC_DZ
#define     FUNC_DZ

#pragma pack(1)

//OFFICE类型
typedef enum _ragEAppType
{
    OFFICE_APP_WORD = 0,
    OFFICE_APP_EXCEL,
}EAppType;

//OFFICE版本返回信息
#define OFFICE_ERROR           (-1)
#define OFFICE_UNKNOWN_ERROR   (-2)
#define OFFICE_VERSION_LOWER   (0)
#define OFFICE_VERSION_2003    (11)
#define OFFICE_VERSION_2007    (12)
#define OFFICE_VERSION_HIGNER  (99)

int GetOfficeVersion(EAppType type);
#pragma pack()

#endif

 

//----------------公共功能库-----------------*/
//#include <afxv_w32.h>
#include <Windows.h>
#include "TheFunc.h"

//获取当前系统OFFICE版本
int GetOfficeVersion(EAppType type)
{
    HKEY         hKey;
    CHAR dir[MAX_PATH] = {0};
    switch(type)
    {
        case OFFICE_APP_WORD:
            strcat(dir , TEXT("
\\Word.Application\\CurVer\\"));
            break;
        case OFFICE_APP_EXCEL:
            strcat(dir , TEXT("
\\Excel.Application\\CurVer\\"));
            break;
        default:
            return OFFICE_ERROR;
    }
    if(::RegOpenKeyExA(HKEY_CLASSES_ROOT , dir , 0 , KEY_READ , &hKey) == ERROR_SUCCESS)
    {
        DWORD type = REG_SZ;
        char value[MAX_PATH]={0};
        DWORD len = MAX_PATH;
        ::RegQueryValueExA(hKey , "" , NULL , &type , (LPBYTE)value , &len);
        ::RegCloseKey(hKey);
        //判断值
        TCHAR tmp[MAX_PATH] = {0};
        int i = strlen(value);
        while(value[i--] !='.')
            ;
        strcpy(tmp , &(value[i + 2]));
        int ver = atoi(tmp);
        switch(ver)
        {
            case 0:
            case 1:
            case 2:
            case 3:
            case 4:
            case 5:
            case 6:
            case 7:
            case 8:
            case 9:
            case 10:
                return OFFICE_VERSION_LOWER;
            case 11:
                return OFFICE_VERSION_2003;
            case 12:
                return OFFICE_VERSION_2007;
            default:
                return OFFICE_VERSION_HIGNER;
        }
    }
    else
        return OFFICE_ERROR;
}

具体应用:

    //监测本机OFFICE(excel)版本
    m_bOffice = TRUE;
    int ver = GetOfficeVersion(OFFICE_APP_EXCEL);
    if(ver == OFFICE_VERSION_2003 || ver == OFFICE_VERSION_LOWER)
        m_OfficeVersion = OFFICE_VERSION_2003;
    else if(ver == OFFICE_VERSION_2007 || ver == OFFICE_VERSION_HIGNER)
        m_OfficeVersion = OFFICE_VERSION_2007;
    else
        m_bOffice = FALSE
;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值