【问题标题】:How to separate CustomUI tags in Excel-DNA from OnAction methods?如何将 Excel-DNA 中的 CustomUI 标签与 OnAction 方法分开?
【发布时间】:2014-02-06 21:50:58
【问题描述】:

在我的 .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 文件中。我做错了什么?

【问题讨论】:

标签: excel-dna


【解决方案1】:

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

应该是:

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

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

【讨论】:

  • 嗨,Govert,我也试过了,但还是没有成功。我已经编辑了我的原始帖子,以准确显示我的代码现在的样子。
  • 但是现在您也更改了功能区 xml 标记。它应该适用于您的原始版本的 .xml 标记,但更正了回调签名。 (虽然“onAction”标签名称可能区分大小写。)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-11-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多