将 Excel-DNA 按钮连接到 C# 代码

Connecting Excel-DNA button to C# code

如何将 Excel-DNA 色带控件连接到 C# 代码中的函数?

我的 DnaLibrary 文件 (.dna) 包含带按钮的功能区。但我不知道如何让 C# 代码在按下时触发。从未调用下面显示的 OnButtonPressed 函数。

这是我的 CustomUI XML:

<CustomUI>
    <customUI xmlns='http://schemas.microsoft.com/office/2009/07/customui' loadImage='LoadImage'>
      <ribbon>
        <tabs>
          <tab id='XLST_Tab' label='XLST'>
            <group id='XLST_Group' label='Standard Time'>
              <button id='BigBtn' label='Press Me' size='large' />
              <button id='BigBtn2' label='Press This Too' size='large' />
            </group>
          </tab>
        </tabs>
      </ribbon>
    </customUI>
</CustomUI>

这是我的 C# 代码:

namespace XLST
{
    [ComVisible(true)]
    public class XLSTRibbon : ExcelRibbon
    {
        public void OnButtonPressed(IRibbonControl control)
        {
            MessageBox.Show("Hello from control " + control.Id);
        }
    }
}

您还需要在功能区中设置 onAction 属性 xml:

<button id='BigBtn' label='Press Me' size='large' onAction='OnButtonPressed' />