VSTO:如何将自定义菜单添加到 Excel 文件菜单

VSTO: How to add custom menu to Excel File menu

使用功能区组件,我添加了一个文件菜单,但是执行后Excel中没有出现,但是当我添加按钮时出现了。

1.Is 可以将菜单组件添加到文件菜单吗?

2.When 我添加了它显示在加载项下的按钮,是否可以在信息之前显示它(请参考图片)?

这是一种使用功能区 XML 并在 TabRecent“打开”选项卡后插入自定义选项卡的方法。 Microsoft Office Fluent User Interface Control Identifiers 仅适用于 Office 2016。我无法使 TabInfo 工作。

这是我找到的参考资料。

后台参考:

  • 首页=PlaceTabHome

  • 新=TabOfficeStart

  • 打开=TabRecent

  • 信息=TabInfo

  • 保存=FileSave

  • 另存为=TabSave

  • 历史 = HistoryTab

  • 打印=TabPrint

  • 分享=TabShare,ShareDocument

  • 导出=TabPublish

  • 发布=Publish2Tab

  • 关闭=FileClose

  • 账户 = TabHelp

  • 意见反馈=TabOfficeFeedback

  • 选项 = TabOptions, ApplicationOptionsDialog


XML 色带代码

<ribbon startFromScratch="false">
</ribbon>
<backstage>
  <tab id="grpMyMenu" label="Annotate" insertAfterMso="TabRecent" visible="true" firstColumnMaxWidth="500">
    <firstColumn>
      <group id="grpOne" label="Microsoft Snipping Tool">
        <primaryItem>
          <button
                id="btnSnippingTool"
                label="Snipping Tool"
                onAction="OnAction"
                getImage="GetButtonImage"
                screentip="Microsoft Snipping Tool"
                supertip="Snipping Tool is a screenshot utility included in Microsoft Windows. It can take screenshots of an open window, rectangular areas, a free-form area, or the entire screen."
                />
        </primaryItem>
        <topItems>
          <layoutContainer id="layoutOne" layoutChildren="horizontal">
            <labelControl id="ebox2" label="Snipping Tool is a screenshot utility included in Microsoft Windows. It can take screenshots of an open window, rectangular areas, a free-form area, or the entire screen." />
          </layoutContainer>
        </topItems>
      </group>
      <group id="grpTwo" label="Microsoft Problem Steps Recorder" >
        <primaryItem>
          <button
                id="btnProblemStepRecorder"
                label="Record Steps"
                onAction="OnAction"
                getImage="GetButtonImage"
                screentip="Microsoft Problem Steps Recorder"
                supertip="Problem Steps Recorder or PSR records the actions you take on your computer which you can then send to the person or group helping you with your computer problem."
                />
        </primaryItem>
        <topItems>
          <labelControl id="ebox3" label="Problem Steps Recorder or PSR records the actions you take on your computer which you can then send to the person or group helping you with your computer problem."/>
        </topItems>
      </group>
    </firstColumn>
  </tab>
</backstage>

C# 代码

    public void OnAction(Office.IRibbonControl control)
    {
        string filePath = string.Empty;
        switch (control.Id)
        {
            case "btnSnippingTool":
                if (System.Environment.Is64BitOperatingSystem)
                {
                    filePath = @"C:\Windows\sysnative\SnippingTool.exe";
                }
                else
                {
                    filePath = @"C:\Windows\system32\SnippingTool.exe";
                }
                System.Diagnostics.Process.Start(filePath);
                break;
            case "btnProblemStepRecorder":
                filePath = @"C:\Windows\System32\psr.exe";
                System.Diagnostics.Process.Start(filePath);
                break;
        }
    }

    public System.Drawing.Bitmap GetButtonImage(Office.IRibbonControl control)
    {
        switch (control.Id)
        {
            case "btnProblemStepRecorder":
                return Properties.Resources.problem_steps_recorder;
            case "btnSnippingTool":
                return Properties.Resources.snipping_tool;
            default:
                return null;
        }
    }

文件选项卡“后台”的屏幕截图