繁体   English   中英

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

[英]add a custom ribbon tag in PowerPoint

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

我遵循了针对 Word 但必须非常相似的MSDN 教程 我为 Word 或 Excel 测试了相同的代码,它可以在功能区中添加“插件”选项卡。 但使用 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>

我的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 :

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

每个文件都在同一个项目下。 你知道我忘记添加插件选项卡出现在 PowerPoint 中吗?

您的代码看起来应该在加载项选项卡下的 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 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 Docs - 演练:使用功能区 XML 创建自定义选项卡

暂无
暂无

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

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