带安装工厂的excel 2010加载项安装项目

时间:2012-05-15 14:45:02

标签: excel installation excel-2010 excel-addins

我正在开发一个excel加载项。我有序列号(例如100 psc),我想检查什么时候在PC上安装excel加载项。但我无法使用VS2010安装项目,因为它不支持序列号列表存储和检查。

所以我想用setup工具做这个,我就像这个链接一样: link

但我有一个问题擅长; enter image description here

如果我选择“是”,则excel正在打开.dll,如果选择“否”,它会执行任何操作。

enter image description here

和我的设置工厂列表一样。 enter image description here

和我的安装工厂“在安装后的脚本上”,我的Addinfilename值是“Posta Guvercini Excel AddIn For 2010.dll”

    -- Determine registry key (2 = HK CURRENT USER)
sVersions = Registry.GetKeyNames(2, "Software\\Microsoft\\Office");

-- Iterate through the registry keys per MS Office-version
--Next line has SetupFactory 8 code
--for iCount1, sVersion in sVersions do    
for iCount1, sVersion in pairs(sVersions) do    

    -- Try opening the registry key
    sSubKey = "Software\\Microsoft\\Office\\"..sVersion..
              "\\Excel\\Options\\"
    sValues = Registry.GetValueNames(2, sSubKey);

    --initialize index counter
    iIndex = -2
    if sValues then

        --Determine the index of the maximimum OPEN registry entry
        --Next line has SetupFactory 8 code
        --for iCount2, sValue in sValues do
        for iCount2, sValue in pairs(sValues) do

            if (String.Left(sValue, 4) == "OPEN") then            
                --Check whether the user did not already install
                --the same add-in to prevent errors when opening Excel
                sKeysValue = Registry.GetValue(2, sSubKey, sValue, true)  
                if String.Find(sKeysValue, SessionVar.Expand(
                              "%AddinFileName%"), 1, false) > 0 then
                    iIndex = -1
                    -- leave loop
                    break;
                else
                    if (sValue == "OPEN") then
                        iIndex = 0
                    else
                        iIndex = String.ToNumber(String.Mid(
                                 sValue, 5, String.Length(sValue)-4))
                    end;
                end;
            end;
        end;

        -- -1 means: This add-in is already installed; we're done
        if iIndex ~= -1 then        
            --Determine path based on variable "%AddinFileName%
            sAppPath = String.Char(34)..
                       SessionVar.Expand("%AppFolder%")..
                       "\\"..
                       SessionVar.Expand("%AddinFileName%")..
                       String.Char(34)

            -- -2 is the initialized value of the index counter
            if (iIndex == -2) then
                -- OPEN-key does not exist
                Registry.SetValue(2, sSubKey, "OPEN",
                                  sAppPath, REG_SZ)
            else
                Registry.SetValue(2, sSubKey, "OPEN"..(iIndex + 1),
                                  sAppPath, REG_SZ)
            end;
        end;
    end;
end;

2 个答案:

答案 0 :(得分:0)

看起来您正在构建自动化插件。
如果是这样,您需要在插件名前加上/ A,告诉Excel它是自动插件。否则它期待XLL或XLA或XLAM

答案 1 :(得分:0)

我解决了这个问题。在进行excel安装时,我们必须使用注册表记录。

result = Registry.SetValue( HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Office\\Excel\\Addins\\company" , "LoadBehavior" , "3" , REG_DWORD );
result = Registry.SetValue(HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Office\\Excel\\Addins\\company" ,"FriendlyName", "program name", REG_SZ);
result = Registry.SetValue( HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Office\\Excel\\Addins\\company" , "Description" , "program name" , REG_SZ );
result = Registry.SetValue(HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Office\\Excel\\Addins\\company" ,"Manifest", SessionVar.Expand("%AppFolder%\\myvtofile.vsto|vstolocal"), REG_SZ);

用于excel启动时的加载项启动。

LoadBehavior键的值应为“3”。