2014-02-06 38 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

相關問題