2017-01-18 19 views
0

如何将Excel-DNA ribbon控件连接到C#代码中的函数?将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); 
     } 
    } 
} 

回答

1

您还需要设置功能区XML的onAction属性:

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