1 /// <summary>
2 /// 获取本地的Word的版本的信息
3 /// </summary>
4 /// <returns>获取的本地Word的版本信息</returns>
5 public static String GetLocalWordVersion(
out String message)
6 {
7 // 返回结果
8 String result =
String.Empty;
9 message =
String.Empty;
10
11 //打开注册表
12 String VBASubKeyPath =
@"SOFTWARE\Microsoft\Shared Tools\AddIn Designer\Visual Basic for Applications IDE";
13 RegistryKey VBASubKey =
Registry.LocalMachine.OpenSubKey(VBASubKeyPath);
14
15 RegistryKey optionKey = Registry.ClassesRoot.OpenSubKey(
"Word.Application\\CurVer");
16 if (optionKey ==
null)
17 {
18 message =
"请安装Office 2007或以上完整版本!";
19 }
20 else
21 {
22 String wordVersion = optionKey.GetValue(
"").ToString();
23
24 if (wordVersion ==
"Word.Application.11")
25 {
26 message =
"您本地的Word版本不支持,需要升级到Office 2007或以上完整版才能完成操作!";
27 }
28 else
29 {
30 if (wordVersion ==
"Word.Application.12"
31 || wordVersion ==
"Word.Application.14")
32 {
33 result =
"2007";
34 }
35 else
36 {
37 Int32 intWordVersion =
0;
38 if (Int32.TryParse(wordVersion.Replace(
"Word.Application.",
""),
out intWordVersion))
39 {
40 if (intWordVersion >=
12)
41 {
42 result =
"2007";
43 }
44 else
45 {
46 message =
"您本地的Word版本不支持,需要升级到Office 2007或以上完整版才能完成操作!";
47 }
48 }
49 else
50 {
51 message =
"您本地的Word版本不支持,需要升级到Office 2007或以上完整版才能完成操作!";
52 }
53 }
54 }
55 }
56
57 return result;
58 }
转载于:https://www.cnblogs.com/huashengdoujiao/p/9792217.html
相关资源:winfrom 获取本地Office版本