views:

143

answers:

3

Good Day,

I need to determine which version of Microsoft Excel is installed on a Windows PC. I'm working with Apache POI but can't figure out an easy way to do this.

Anyone know if Apache POI has a built in functionality to do this? Any ideas how to do this using Java code?

Thanks in advance.

A: 

Ok it just occured to me that older Microsoft Excel versions have file extensions .xls and new ones have .xlsx.

I can just get reference to the file and get the file extensions... that easy.

If anyone has a better solution please let me know.

Marquinio
You do realize that it's possible for an older version of Excel to open, read and modify .xlsx documents using the compatibility pack here: http://support.microsoft.com/kb/924074
ig0774
+2  A: 

I really, really don't think POI has this functionality, as it's explicitly written to work cross-platform. It only deals with document files.

If I were faced with this task, I'd dig into the registry (via the Windows API) for the association of the .XLS file type. That will, err should give you a link to the most recently and completely installed Excel. Not reliably, because

  • there might not be an Excel installed;
  • the user might have changed the association; or
  • the Excel pointed at by the association might be broken.

But given the hint of (usually) the applicable executable, you could then examine either the .EXE file header of Excel or perhaps something in the surrounding files to determine Excel's version.

Carl Smotricz
+3  A: 

POI provides a mechanism for writing Excel documents without using any of the Excel APIs. I doubt it has a mechanism to detect the installed version, as it has no dependency on an installed version of Excel.

Following a pattern similar to the one described in this question about detecting the Excel version in .NET, you could use JACOB to detect the installed Excel version like so:

ActiveXComponent xl = new ActiveXComponent("Excel.Application");
try {
    xl.getProperty("Version");
} finally {
    xl.invoke("Quit", new Variant[] {});
}
ig0774
Now that's slick, +1! Being a Windows hater, I never think to use COM for this kind of stuff.
Carl Smotricz
And congratulations on 1000 :)
Carl Smotricz
@Carl Smotricz: Thanks!
ig0774