最近在做一个C#操作word的程序,由于word有多个版本,每个版本的com组件不一样,所以不能在项目中引用固定的com组件,只能动态调用,因此想到了之前略过的反射,各种网页搜了半天,自己写写改改,终于可以运行了。
- 首先读出注册表中的word版本
public class TestOffice { public static void GetWordVersion(out int wordVerNum, out string wordAppName) { //word版本号 wordVerNum = 0; //word应用程序名称 wordAppName = null; string str_KeyName = "Path"; object objResult = null; Microsoft.Win32.RegistryValueKind regValueKind;//指定在注册表中存储值时所用的数据类型,或标识注册表中某个值的数据类型。 Microsoft.Win32.RegistryKey regKey = null;//表示 Windows 注册表中的项级节点(注册表对象?) Microsoft.Win32.RegistryKey regSubKey = null; try { regKey = Microsoft.Win32.Registry.LocalMachine;//读取HKEY_LOCAL_MACHINE项 //office2010 if (regSubKey == null) {