我有一个c++非托管项目,它的输出是一个.xll文件,这是一个插件加载的excel在启动时,这个插件可以与两个版本,excel 2003和excel 2007。
现在,我需要做的是获取用户实际使用我的外接程序时所使用的excel实例的版本。
有没有人能建议我怎么拿到它?
谢谢
发布于 2009-09-03 06:49:32
您可以调用Excel4(xlfGetWorkspace,& version,1,& arg ),其中arg是设置为2的数字XLOPER,version是字符串XLOPER,然后可以强制将其转换为整数。
Excel 2007的结果将是12。
您可以在xlAutoOpen中做到这一点。
发布于 2009-09-03 08:51:17
Len Holgate给出了正确的答案,以找出正在使用的Excel的版本号。下面是一些示例代码:
xloper xlstrVersion, xlintVersion, xlintParam;
// supply a parameter with value 2 to read the Excel version number as a string
xlintParam.xltype = xltypeInt;
xlintParam.val.w = 2;
int xlret = Excel4(xlfGetWorkspace, &xlstrVersion, 1, &xlintParam);
// now use the xlCoerce function to convert the version string to an integer
xlintParam.val.w = xltypeInt;
xlret = Excel4(xlCoerce, &xlintVersion, 2, &xlstrVersion, &xlintParam);
const int ExcelVersion = xlintVersion.val.w;
const bool ExcelVersion12Plus = ExcelVersion >= 12;如果您只需要区分Excel12版和早期版本,请使用XLCallVer函数,如下所示:
const bool ExcelVersion12Plus = (0x0c00 == XLCallVer());发布于 2009-09-02 22:09:34
这可能是离题的,但是GetFileVersionInfo函数将返回VERSION_INFO结构,您可以在其中使用VerQueryValue函数来检索文件版本。缺点是您必须找到可执行文件的路径,如果您拥有GetModileFileName实例的句柄,则可以使用Excel函数完成此操作。
https://stackoverflow.com/questions/1370375
复制相似问题