开发者

Determine installed Microsoft Excel version using Apache POI?

I need to determine which version of Microsoft Excel is installed on 开发者_StackOverflow社区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?


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[] {});
}


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜