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



我尝试使用C#中的VSTO在PowerPoint中添加一个自定义功能区选项卡(在功能区中,我想添加一个按钮(

我遵循了旨在言语但必须非常相似的MSDN教程。我测试了Word或Excel的相同代码,它可以使用AD AD" ADDIN"选项卡中添加到功能区中。但是使用PowerPoint却没有。

我的代码。这里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:

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:

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

每个文件都在同一项目下。您知道我忘记了添加addin选项卡的内容吗?

您的代码看起来应该在"加载项"选项卡下的PowerPoint Menuebar中找到您的自定义功能区选项卡。如果要创建自己的选项卡,请将您的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>

我希望这对您或其他人有帮助。如果您想了解更多信息,请参阅Microsoft文档 - 演练:使用功能区XML

创建自定义选项卡

最新更新