在PowerPoint

时间:2018-04-05 06:11:26

标签: c# office-addins

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

我关注了MSDN tutorial,它是针对Word的,但必须非常相似。 我为Word或Excel测试了相同的代码,它可以使用" 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();
}

每个文件都在同一个项目下。 你知道我忘记添加插件显示在PowerPoint吗?

1 个答案:

答案 0 :(得分:0)

您的代码看起来发现您的自定义功能区选项卡应该在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 - Walkthrough: Create a custom tab by using Ribbon XML