본문 바로가기

Program/Delphi

[Delphi] Excel 경로 및 Office 버전 찾기.

uses절에 Registry 추가.

uses Registry;


procedure TForm1.FormCreate(Sender: TObject);
begin
  ShowMessage(GetOfficeVersion(GetExcelPath));
end;

function TForm1.GetExcelPath: string;
var
  tempRegistry: TRegistry;
begin
  tempRegistry := TRegistry.Create;

  try
    tempRegistry.RootKey := HKEY_LOCAL_MACHINE;

    if tempRegistry.OpenKey('SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\excel.exe', False) then
      Result := tempRegistry.ReadString('Path') + 'excel.exe';

  finally
    tempRegistry.Free;
  end;
end;

function TForm1.GetOfficeVersion(pExcelPath: string): string;
begin
  if pExcelPath <> '' then
  begin
    Result := Copy(pExcelPath, Length(pExcelPath) - 11, 2);
  end;
end;


[버전에 따른 Offce제품]

* 11(Office11) : Office 2003

* 12(Office12) : Office 2007

* 14(Office14) : Office 2010

* 15(Office15) : Office 2013


특정 소프트웨어의 정보가 필요하다면 위와 비슷한 방법으로 Registry 정보를 통해 OS에 설치된 소프트웨어의 정보를 가져오면 됨.