2014-02-06 37 views
0

在我。DNA文件我有:如何将Excel-DNA中的CustomUI标签与OnAction方法分开?

<DnaLibrary Name="First Add-In" RuntimeVersion="v4.0" Language="C#"> 
    <ExternalLibrary Path="MyLibrary.dll" Pack="true"/> 
    <Image Name="M" Path="M.png" Pack="true" /> 
    <CustomUI> 
    <customUI xmlns='http://schemas.microsoft.com/office/2009/07/customui' loadImage='LoadImage'> 
     <ribbon> 
     <tabs> 
      <tab id='CustomTab' label='My 2010 Tab'> 
      <group id='SampleGroup' label='My Sample Group'> 
       <button id='Button1' label='My Second Button' image='M' size='normal' onAction='RunTagMacro' tag='ReformatSelection='/> 
      </group > 
      </tab> 
     </tabs> 
     </ribbon> 
    </customUI> 
    </CustomUI> 
</DnaLibrary> 

在我的.cs文件我有:

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using System.Threading.Tasks; 
using ExcelDna.Integration; 
using System.Runtime.InteropServices; 
using ExcelDna.Integration.CustomUI; 
using System.Windows.Forms; 

namespace MyLibrary 
{ 
    [ComVisible(true)] 
    public class Class1 : ExcelRibbon 
    {     

     public void ReformatSelection(IRibbonControl control) 
     { 
      MessageBox.Show("Hello"); 
     } 
    } 
} 

当我加载插件按钮和选项卡功能区中显示正常,但点击按钮不会运行ReformatSelection方法。在Excel-DNA提供的示例文件中,挂钩到onAction事件的所有子和函数都位于.dna文件中。我正试图将它们移出.dna文件并放入.cs文件中。我究竟做错了什么?

+0

同样的问题在这里还讨论:https://groups.google.com/论坛/#!主题/ exceldna/mMBjb4xvH4k – Govert

回答

1

您的签名ReformatSelection()不适用于功能区按钮的onAction处理程序。

它应该是:

public void ReformatSelection(IRibbonControl control) {...} 

你可以得到所有的Office功能区回调这里签名的列表:http://msdn.microsoft.com/en-us/library/aa722523(v=office.12).aspx

+0

嗨戈夫特,我也试过,但仍然没有运气。我编辑了我的原始帖子,以准确显示我的代码现在的样子。 –

+0

但是现在您已经更改了功能区xml标记了。它应该与您的原始版本的.xml标记一起使用,但应该使用更正的回调签名。 (尽管“onAction”标签名称可能区分大小写。) – Govert

相关问题