首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用java在您的pc上了解MS-Office版本

使用java在您的pc上了解MS-Office版本
EN

Stack Overflow用户
提问于 2010-02-28 16:47:07
回答 3查看 679关注 0票数 1

有没有办法知道我的电脑上使用的是哪个版本的MS-Office?

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2010-02-28 17:31:57

我可以建议你做一些棘手的工作:

您可以很容易地获得已安装字体的列表。不同版本的MS-Office有不同的独特字体。你需要用谷歌搜索哪个字体对应哪个版本,它会给你一些信息(例如,如果你能看到'Constantia‘,那么它就是Office2007)。

票数 2
EN

Stack Overflow用户

发布于 2010-02-28 16:52:25

在ms office的安装中是否有一个特定的文件来区分不同的版本?如果是,你可以阅读它并检测。

否则,您将不得不与可能安装的(操作系统) ms office activex控件进行繁琐的交互,并查询版本号。

票数 1
EN

Stack Overflow用户

发布于 2013-08-27 22:53:29

一种方法是调用Windows ASSOC和FTYPE命令,捕获输出并对其进行解析,以确定安装的Office版本。

代码语言:javascript
复制
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代码:

代码语言:javascript
复制
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

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/2350543

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档