2010-06-03 112 views
0

我创建了下面的自动化插件:Excel自动化加载项的UDF不能入店

namespace AutomationAddin 
{ 
    [Guid("6652EC43-B48C-428a-A32A-5F2E89B9F305")] 

    [ClassInterface(ClassInterfaceType.AutoDual)] 
    [ComVisible(true)] 
    public class MyFunctions 
    { 
     public MyFunctions() 
     { 
     } 

     #region UDFs 
     public string ToUpperCase(string input) 
     { 
      return input.ToUpper(); 
     } 
     #endregion 

     [ComRegisterFunctionAttribute] 
     public static void RegisterFunction(Type type) 
     { 
      Registry.ClassesRoot.CreateSubKey(
      GetSubKeyName(type, "Programmable")); 

      RegistryKey key = Registry.ClassesRoot.OpenSubKey(
       GetSubKeyName(type, "InprocServer32"), true); 

      key.SetValue("", 
       System.Environment.SystemDirectory + @"\mscoree.dll", 
       RegistryValueKind.String); 
     } 

     [ComUnregisterFunctionAttribute] 
     public static void UnregisterFunction(Type type) 
     { 
      Registry.ClassesRoot.DeleteSubKey(
       GetSubKeyName(type, "Programmable"), false); 
     } 

     private static string GetSubKeyName(Type type, 
      string subKeyName) 
     { 
      System.Text.StringBuilder s = 
       new System.Text.StringBuilder(); 

      s.Append(@"CLSID\{"); 
      s.Append(type.GUID.ToString().ToUpper()); 
      s.Append(@"}\"); 
      s.Append(subKeyName); 

      return s.ToString(); 
     } 
    }  
} 

我建立它和它注册就好了。我打开excel 2003,进入工具 - >加载项,点击自动化按钮,插件出现在列表中。我添加它,它显示在插件列表中。但是,函数本身不会出现。如果我输入它不起作用,并且如果我查看功能向导,我的插件不会显示为一个类别,并且功能不在列表中。

我在Windows 7 x86上使用excel 2003。我使用Visual Studio 2010构建了这个项目。这个插件在Visual Studio 2008构建的windows xp上运行良好。

回答

0

事实证明,CLR没有正常工作,安装了一个补丁,现在它可以正常工作。