知道您的电脑上使用java的MS-Office版本
答
我可以建议你有点棘手变通:
您可以方便地安装的字体列表。不同版本的MS-Office具有不同的独特字体。你需要谷歌哪些字体对应于哪个版本,它可以给你一些信息(例如,如果你可以看到'康斯坦蒂亚',那么它是办公室2007年)。
答
在ms office的安装中是否有特定的文件区分一个版本和另一个版本?如果是,你可以阅读并检测。
其他你需要做的与可能安装(到O/S)MS Office ActiveX控件的接口,并查询版本号。
答
一种方法是调用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" /e
Java代码:
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();
}
}
}
你可以有多个版本,你想要什么,知道扩展名为.doc例如相关的人吗? –
我想知道MS-Excel的版本,以便我可以使用适当的API。 – Supereme