Supereme
Supereme

Reputation: 2409

Knowing MS-Office version on Your pc using java

Is there any way to know which version of MS-Office I have on my pc using 'Java'?

Upvotes: 1

Views: 746

Answers (3)

RealHowTo
RealHowTo

Reputation: 35372

One way is to call the Windows ASSOC and FTYPE commands, capture the output and parse it to determine the Office version installed.

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 code :

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();
      }
    }
  }

Upvotes: 1

Roman
Roman

Reputation: 66156

I can suggest you a bit tricky work around:

You can easily get list of installed fonts. Different versions of MS-Office have different unique fonts. You need to google which fonts correspond to which version and it can give you some information (for example, if you can see 'Constantia' then it's office 2007).

Upvotes: 2

cherouvim
cherouvim

Reputation: 31903

Is there a specific file in the installation of ms office that distinguishes one version from another? If yes you could read that and detect.

Other you'd have to do nasty interfacing with the possibly installed (to the o/s) ms office activex controls and query the version number.

Upvotes: 1

Related Questions