有没有办法知道我的电脑上使用的是哪个版本的MS-Office?
发布于 2010-02-28 17:31:57
我可以建议你做一些棘手的工作:
您可以很容易地获得已安装字体的列表。不同版本的MS-Office有不同的独特字体。你需要用谷歌搜索哪个字体对应哪个版本,它会给你一些信息(例如,如果你能看到'Constantia‘,那么它就是Office2007)。
发布于 2010-02-28 16:52:25
在ms office的安装中是否有一个特定的文件来区分不同的版本?如果是,你可以阅读它并检测。
否则,您将不得不与可能安装的(操作系统) ms office activex控件进行繁琐的交互,并查询版本号。
发布于 2013-08-27 22:53:29
一种方法是调用Windows ASSOC和FTYPE命令,捕获输出并对其进行解析,以确定安装的Office版本。
C:\Users\me>assoc .xls
.xls=Excel.Sheet.8
C:\Users\me>ftype Excel.sheet.8
Excel.sheet.8="C:\Program Files (x86)\Microsoft Office\Office12\EXCEL.EXE" /eJava代码:
import java.io.*;
public class ShowOfficeInstalled {
public static void main(String argv[]) {
try {
Process p = Runtime.getRuntime().exec
(new String [] { "cmd.exe", "/c", "assoc", ".xls"});
BufferedReader input =
new BufferedReader
(new InputStreamReader(p.getInputStream()));
String extensionType = input.readLine();
input.close();
// extract type
if (extensionType == null) {
System.out.println("no office installed ?");
System.exit(1);
}
String fileType[] = extensionType.split("=");
p = Runtime.getRuntime().exec
(new String [] { "cmd.exe", "/c", "ftype", fileType[1]});
input =
new BufferedReader
(new InputStreamReader(p.getInputStream()));
String fileAssociation = input.readLine();
// extract path
String officePath = fileAssociation.split("=")[1];
System.out.println(officePath);
//
// output if office is installed :
// "C:\Program Files (x86)\Microsoft Office\Office12\EXCEL.EXE" /e
// the next step is to parse the pathname but this is left as an exercise :-)
//
}
catch (Exception err) {
err.printStackTrace();
}
}
}参考:Detect the installed Office version
https://stackoverflow.com/questions/2350543
复制相似问题