简体   繁体   English

在 PowerPoint 中添加自定义功能区标签

[英]add a custom ribbon tag in PowerPoint

I try to add a custom ribbon tab in PowerPoint using VSTO in C# (in the ribbon, I want to add a button)我尝试在 PowerPoint 中使用 C# 中的 VSTO 添加自定义功能区选项卡(在功能区中,我想添加一个按钮)

I followed the MSDN tutorial which is intended to Word but must be very similar.我遵循了针对 Word 但必须非常相似的MSDN 教程 I tested the same code for Word or Excel it works ad an "Addin" Tab is added to the ribbon.我为 Word 或 Excel 测试了相同的代码,它可以在功能区中添加“插件”选项卡。 But with PowerPoint it doesn't.但使用 PowerPoint 则不然。

My code.我的代码。 Here MyRibbon.xml:这里是 MyRibbon.xml:

<?xml version="1.0" encoding="UTF-8"?>
<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui" onLoad="Ribbon_Load">
  <ribbon>
    <tabs>
      <tab idMso="TabAddIns">
        <group id="ContentGroup" label="Content">
          <button id="textButton" label="Insert Text"
               screentip="Text" onAction="OnTextButton"
               supertip="Inserts text at the cursor location."/>
          <button id="tableButton" label="Insert Table"
               screentip="Table" onAction="OnTableButton"
               supertip="Inserts a table at the cursor location."/>

        </group>
      </tab>
    </tabs>
  </ribbon>
</customUI>

MyRibbon.cs:我的Ribbon.cs:

public class MyRibbon : Office.IRibbonExtensibility
    {
        private Office.IRibbonUI ribbon;

        public MyRibbon()
        {
        }

        public string GetCustomUI(string ribbonID)
        {
            return GetResourceText("PowerPointAddIn2.MyRibbon.xml");
        }

        public void Ribbon_Load(Office.IRibbonUI ribbonUI)
        {
            this.ribbon = ribbonUI;
        }

        public void OnTextButton(Office.IRibbonControl control)
        {
            MessageBox.Show("This text was added by the Ribbon.");
        }

ThisAddin.cs : ThisAddin.cs :

private void ThisAddIn_Startup(object sender, System.EventArgs e){}
private void ThisAddIn_Shutdown(object sender, System.EventArgs e){}

protected override Microsoft.Office.Core.IRibbonExtensibility CreateRibbonExtensibilityObject()
{
    return new MyRibbon();
}

Every files are under the same project.每个文件都在同一个项目下。 Do you know what I have forgotten to add the addin Tab appear in PowerPoint ?你知道我忘记添加插件选项卡出现在 PowerPoint 中吗?

your code looks find that your custom ribbon tab should be found within the PowerPoint menuebar under the add-in tab.您的代码看起来应该在加载项选项卡下的 PowerPoint 菜单栏中找到您的自定义功能区选项卡。 If you want to create your own tab, change your MyRibbon.xml code to:如果要创建自己的选项卡,请将 MyRibbon.xml 代码更改为:

<?xml version="1.0" encoding="UTF-8"?>
<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui" onLoad="Ribbon_Load">
  <ribbon>
    <tabs>
      <tab id="MyRibbonTab" label="MyRibbon">
        <!-- idMso="TabAddIns" -->
        <group id="ContentGroup" label="Content">
          <button id="textButton" label="Insert Text"
               screentip="Text" onAction="OnTextButton"
               supertip="Inserts text at the cursor location."/>
          <button id="tableButton" label="Insert Table"
               screentip="Table" onAction="OnTableButton"
               supertip="Inserts a table at the cursor location."/>

        </group>
      </tab>
    </tabs>
  </ribbon>
</customUI>

I hope this helps you or others.我希望这对您或其他人有所帮助。 If you want to learn more see Microsoft Docs - Walkthrough: Create a custom tab by using Ribbon XML如果要了解更多信息,请参阅Microsoft Docs - 演练:使用功能区 XML 创建自定义选项卡

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM