3

내 프로그램에서 Excel 파일을로드해야합니다. 이 파일의 확장명은 [.xls] [. xlsx] [. xlsm] [. xlsb]입니다.Office2003 호환 팩이 설치되어 있습니까?

Excel07 + 자연이 모든 것을 처리 할 수 ​​있지만, [.XLSX] 작업을 [. XLSM] [. XLSB] Excel2003에서 당신이 여기서 결정하기 위해 내 코드입니다 http://www.microsoft.com/en-us/download/details.aspx?id=3

를 설치해야하는 excelversion 설치되어 있습니다. 문제점 : 호환성 팩 (+++로 표시)의 설치 방법을 모르겠다. (+++로 표시)

if (ExtractFileExt(sFileNameVorlage) = '.xlsx') or 
    (ExtractFileExt(sFileNameVorlage) = '.xlsm') or 
    (ExtractFileExt(sFileNameVorlage) = '.xlsb') then 
    begin 

    //determine version of excel (lower or equal 2003) 
    if StrToInt(Copy(oVersionscheck.version,1,2)) <= 11 then 
    begin 

     // equal 2003 
     if StrToInt(Copy(oVersionscheck.version,1,2)) = 11 then 
     if not +++compatibility pack installed?+++ then 
     begin  
      ShowMessage('Warning: Excel can´t open this file.'); 
      oVersionscheck.Quit; 
      oVersionscheck := unassigned; 
      Exit; 
     end; 
     end; 
     oVersionscheck.Quit; 
end; 

누군가가 해결책을 알고있을 것입니다. 당신은 선택의 여지가 귀하의 프로그래밍 언어로 번역해야 할 수 있도록

답변

2

나는 http://www.tech-archive.net/Archive/Word/microsoft.public.word.vba.general/2008-10/msg00682.html

이것은 VBA 함수이다에서 다음과 같은 답을 발견했다. (현대 언어에서는 "On Error Resume Next"대신 Try/Catch 절을 사용함)

Function Office2007CompatibilityInstalled() 
'Checks whether in Office 2003 the compatibility pack for Office 2007/2010 is installed 
    Dim WSHShell, RegKey, rKeyWord, Result 
    Set WSHShell = CreateObject("WScript.Shell") 
    RegKey = "HKEY_CLASSES_ROOT\Installer\Products\00002109020090400000000000F01FEC\" 

    On Error Resume Next 'This is in an anticipation of what may happen in the next line 
    'The next line will generate an error if the registry key does not exist. 
    'This error will be ignored and execution will continue with the line following 
    'it (because of "On Error Resume Next" statement). In this case the value of 
    'rKeyWord will remain uninitialised. 
    rKeyWord = WSHShell.RegRead(RegKey & "ProductName") 
    'In the line below we compare the value of rKeyWord to a fixed string which we 
    'know to denote that Office2007 Compatibility Pack has been installed. 
    'If the registry key did not exist then the value of rKeyWord will be uninitialised 
    'and will be automatically converted to an empty string ("") for the purposes 
    'of this comparison. 
    If rKeyWord = "Compatibility Pack for the 2007 Office system" Then 
     Office2007CompatibilityInstalled = True 
    End If 
End Function