I had a problem setting a custom label on a fly with a ribbon using Excel-DNA.
If I do not include the annotation "getLabel =" GetLabel ", then the plugin loads fine. Ie, the ribbon tab is shown with 2 buttons, and the button callbacks work fine.
If I enable the getLabel = GetLabel property, then the plugin does not even load, that is, onLoad is not called, and the ribbon tab does not appear in excel.
Can anyone see what I'm doing wrong here. I do not see errors when working in the debugger.
Here is my DNA file. I tried to base it on one of the patterns to make it easier to follow.
<DnaLibrary Name="Emsx Addin" RuntimeVersion="v2.0"> <ExternalLibrary Path="EmsxExcelTech1.dll" /> <Reference AssemblyPath="System.Windows.Forms.dll" /> <Image Name="M" Path="M.png" Pack="true" /> <CustomUI> <customUI xmlns='http://schemas.microsoft.com/office/2009/07/customui' loadImage='LoadImage' onLoad='OnLoad'> <ribbon> <tabs> <tab id='CustomTab' label='K2 Emsx' insertAfterMso='View'> <group id='SampleGroup' label='Global Sheet Status'> <button id='LoginCmd' label='Logon' image='M' onAction='OnLogonPressed' getLabel='GetLabel' /> <button id='BetaCmd' label='Use Beta Route' image='M' size='normal' onAction='RunTagMacro' tag='OnUseBetaRoutes' /> </group > </tab> </tabs> </ribbon> </customUI> </CustomUI> </DnaLibrary>
Here is my CBS file obtained from the tape.
[ComVisible(true)] public class EmsxRibbon : ExcelRibbon { private IRibbonUI ribbon = null; public void OnLogonPressed(IRibbonControl control) { EmsxIntegration.Instance.Login(); MessageBox.Show("Hello from control " + control.Id); if (ribbon != null) { ribbon.InvalidateControl(control.Id); } } string GetLabel(IRibbonControl control) { if (control.Tag == "Logon") { return "Logon"; } else { return "Logoff"; } } public static void OnUseBetaRoutes() { MessageBox.Show("Hello from 'ShowHelloMessage'."); } public void OnLoad(IRibbonUI ribbon) { this.ribbon = ribbon; } }
source share