【问题标题】:Office2003 compatibility pack installed?Office2003兼容包装了吗?
【发布时间】:2012-11-15 11:24:33
【问题描述】:

在我的程序中,我必须加载一个 excel 文件。此文件可以具有以下扩展名:[.xls][.xlsx][.xlsm][.xlsb]。

Excel07+ 可以自然处理所有这些问题,但要在 Excel2003 中使用 [.xlsx][.xlsm][.xlsb],您必须安装 http://www.microsoft.com/en-us/download/details.aspx?id=3

这是我的代码来确定,安装了哪个 excel 版本。问题:我不知道如何确定是否安装了兼容包(标记为 +++)

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;

也许有人知道解决方案。

【问题讨论】:

    标签: excel-2007 excel-2003 file-extension delphi-5 early-binding


    【解决方案1】:

    我在http://www.tech-archive.net/Archive/Word/microsoft.public.word.vba.general/2008-10/msg00682.html找到了以下答案

    这是一个 VBA 函数,因此您可能需要将其翻译成您选择的编程语言。 (在更现代的语言中,使用 Try/Catch 子句而不是“On Error Resume Next”)

    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
    

    【讨论】:

      猜你喜欢
      • 2020-08-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-28
      相关资源
      最近更新 更多