简体   繁体   中英

Detect Version of Excel in Delphi

I am currently using the following code to check to see if the Excel Automation libraries exist on the user's computer:

  CoInitialize(nil);
  ExcelExists := true;
  try
    TestExcel := CreateOleObject('Excel.Application');
  except
    ExcelExists := false;
  end;
  if ExcelExists then begin
    TestExcel.Workbooks.Close;
    TestExcel.Quit;
    TestExcel := Unassigned;
  end;

This has been working fine until one user only had Excel 2003. The above code said he had Excel, however my Excel automation does not work for him, and I suspect it won't work for versions prior to Excel 2003 either.

How can I check that the version of Excel that is installed is 2007 or later?


Based on David's answer, I ended up putting this after the if ExcelExists statement and it seems to do the job:

S := TestExcel.Application.Version;
if (copy(S, 3, 1) <> '.') or (S < '12') then
  ExcelExists := false;

Version 12 was Office 2007.

Read the Version property of the Excel Application object. Compare this against the minimum value that your code supports.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM