0

在我的 .dna 文件中,我有:

<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 文件中。我究竟做错了什么?

4

1 回答 1

1

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

它应该是:

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

您可以在此处获取所有 Office 功能区回调签名的列表:http: //msdn.microsoft.com/en-us/library/aa722523 (v=office.12).aspx

于 2014-02-06T13:12:42.723 回答