2005. április 27., szerda

Detect if Excel is installed


Problem/Question/Abstract:

In the application I am writing I need to get data from an Excel spreadsheet and then insert it into a database. I am going to automate Excel. What I would like to know is how I can detect to see if excel is installed, and if it is, what version of Excel is on the user's computer. How can I do this?

Answer:

{ ... }
var
  ClassID: TCLSID;
  strOLEObject: string;
begin
  strOLEObject := 'Excel.Application';
  if (CLSIDFromProgID(PWideChar(WideString(strOLEObject)), ClassID) = S_OK) then
  begin
    {application is installed}
  end
  else
  begin
    {application is not installed}
  end
end;

To get the version, just read Version property of Excel.Application:

xls := CreateOLEObject('Excel.Application');
v := xls.Version;

Nincsenek megjegyzések:

Megjegyzés küldése