Excel 自动化插件 UDF 无法访问

发布于 2024-09-04 12:28:15 字数 1783 浏览 3 评论 0原文

我创建了以下自动化插件:

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 上运行良好。

I created the following automation addin:

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();
        }  
    }    
}

I build it and it registers just fine. I open excel 2003, go to tools->Add-ins, click on the automation button and the addin appears in the list. I add it and it shows up in the addins list. but, the functions themselves don't appear. If I type it in it doesn't work and if I look in the function wizard, my addin doesn't show up as a category and the functions are not in the list.

I am using excel 2003 on windows 7 x86. I built the project with visual studio 2010. This addin worked fine on windows xp built with visual studio 2008.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

眼泪都笑了 2024-09-11 12:28:15

事实证明 CLR 无法正常工作,安装了补丁后现在可以正常工作了。

turns out CLR wasn't working right, installed a patch and now it works.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文