检查excel 2010位数

时间:2012-10-19 13:16:29

标签: c# visual-studio excel vsto office-interop

是否可以使用 getBinaryType()函数获取office 2010位数,该函数在kernel32.dll中定义,如下所示。

[DllImport("kernel32.dll")]
static extern bool GetBinaryType(string lpApplicationName, out uint lpBinaryType);

uint type;
GetBinaryType("applicationName",out type);

我已尝试使用如下所述的应用程序类,但有时会失败。

 public static ExcelVersion GetExcelVersion(object applicationClass)
        {
            if (applicationClass == null)
                throw new ArgumentNullException("applicationClass");

            PropertyInfo property = applicationClass.GetType().GetProperty("HinstancePtr", BindingFlags.Instance | BindingFlags.Public);
            if (property == null)
                return ExcelVersion.Excel;

            return (System.Runtime.InteropServices.Marshal.SizeOf(property.GetValue(applicationClass, null)) == 8) ? ExcelVersion.Excel2010_64 : ExcelVersion.Excel2010_32;
}

还有其他方法可以检测 office 2010 位数吗?

1 个答案:

答案 0 :(得分:1)

我会做的是

1)打开以下注册表项:

HKEY_CLASSES_ROOT\CLSID\{00024500-0000-0000-C000-000000000046}\LocalServer

(guid表示“Excel申请”)

2)从密钥的默认值中提取Excel的.EXE路径(您要删除所有命令行参数)

3)在路径上使用GetBinaryType

相关问题