Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 要加载项的单词_C#_Ms Word_Vsto - Fatal编程技术网

C# 要加载项的单词

C# 要加载项的单词,c#,ms-word,vsto,C#,Ms Word,Vsto,我正在为Microsoft Office Word开发外接程序,遇到了一个不寻常的情况。在我的外接程序中,我想在用户右键单击表格单元格时再添加几个选项。我编写了一个小函数,用于创建/搜索我的外接程序按钮: private Office.CommandBarButton AppendBarButton(Office.CommandBar cmdBar, string tag, string caption, int? faceid = null, bool begingroup = fal

我正在为Microsoft Office Word开发外接程序,遇到了一个不寻常的情况。在我的外接程序中,我想在用户右键单击表格单元格时再添加几个选项。我编写了一个小函数,用于创建/搜索我的外接程序按钮:

    private Office.CommandBarButton AppendBarButton(Office.CommandBar cmdBar, string tag, string caption, int? faceid = null, bool begingroup = false)
    {
        if (cmdBar == null) throw new ArgumentNullException("Command bar argument cannot be null.");
        if (string.IsNullOrWhiteSpace(tag)) throw new ArgumentException("Invalid tag.");
        if (string.IsNullOrWhiteSpace(caption)) throw new ArgumentException("Invalid caption.");

        Office.CommandBarButton btn = cmdBar.Controls.OfType<Office.CommandBarButton>().FirstOrDefault(ctrl => ctrl.Tag == tag);
        if (btn == null) btn = (Office.CommandBarButton)cmdBar.Controls.Add(Office.MsoControlType.msoControlButton, Type.Missing, Type.Missing, Type.Missing, true);
        if (btn == null) throw new ApplicationException("Could not create the command bar button.");

        btn.Tag = tag;

        if (faceid != null)
        {
            btn.Style = Office.MsoButtonStyle.msoButtonIconAndCaption;
            btn.BuiltInFace = true;
            btn.FaceId = (int)faceid;
        }
        else btn.Style = Office.MsoButtonStyle.msoButtonCaption;

        btn.Caption = caption;
        btn.BeginGroup = begingroup;

        return btn;
    }
现在是奇怪的部分。这个很好用。我在我的开发笔记本电脑上测试它,它工作正常。我将它部署在我的另一台笔记本电脑上(通过发布,然后安装在笔记本电脑上),它工作正常,再次正常工作。然而,在我客户的两台笔记本电脑上,我的部署方式与在另一台笔记本电脑上相同,但它似乎不起作用。所有4台笔记本电脑都安装了Office 2016。外接程序的所有其他功能都正常工作,除了这个

我不能确定问题是否出在代码的这一部分,但问题是。我已经尝试/捕获并记录了几乎所有的代码。除了
SomeBtnClickHandler
(用[!!!]标记)之外,所有笔记本电脑上的记录都与它应该记录的完全一样。似乎当我按下客户端笔记本电脑上的按钮时,处理程序根本不会被调用(是的,这似乎确实是个问题,因为在我的2台笔记本电脑上,该处理程序的功能发生了变化,我可以看到变化——就像它真的被调用了一样,但是在我客户的笔记本电脑上,绝对没有发生任何变化,文档和日志中都没有预期的变化。)我至少希望函数工作不正常,行[!!!]会引发某种异常,甚至可能是NRE


我还不熟悉VSTO,所以可能忽略了一些简单的东西。

自从Office 2010引入完整的RibbonX功能以来,CommandBars对象模型已被弃用。我建议您使用Ribbon XML(而不是设计器)向此快捷菜单添加按钮。@Cindymister我会尝试,谢谢您的建议。
    var tableCellsBar = Globals.ThisAddIn.Application.CommandBars["Table Cells"];
    var someBtn = AppendBarButton(tableCellsBar, "HardCodedTag", "SomeCaption", 989);
    someBtn.Click += SomeBtnClickHandler; // [!!!]