Can't change the label on an excel ribbon
Asked Answered
S

1

6

I've got a problem trying to set a custom label on teh fly with a ribbon using Excel-DNA.

If I don't included the annotation "getLabel='GetLabel'" then the plugin loads fine. ie the ribbon tab is shown with 2 buttons andthe button callbacks work fine.

If I do inclue the property "getLabel='GetLabel'" then the plugin doesn't even load, ie onLoad isn't called and the ribbon tab doesn't show up in excel.

Can anyone see what I'm doing wrong here. I don't see any errors when running in the debugger.

Here is my DNA file. I've tried to base it off one of the samples so it's easier to follow.

<DnaLibrary Name="Emsx Addin" RuntimeVersion="v2.0">
<ExternalLibrary Path="EmsxExcelTech1.dll" />
<Reference AssemblyPath="System.Windows.Forms.dll" />

<!-- Some images that can be used in the Ribbon ui -->
<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 Ribbon derived C# file.

[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;
    }

}
Skim answered 19/2, 2013 at 20:59 Comment(1)
Maybe you can't have a "label" and a "getLabel" in the xml?Dustcloth
A
8

When you use the getLabel event, you should not use label property, so change

<button id='LoginCmd' label='Logon' image='M' onAction='OnLogonPressed' getLabel='GetLabel' />

to

<button id='LoginCmd' image='M' onAction='OnLogonPressed' getLabel='GetLabel' />

Hope this helps.

Atlantean answered 21/5, 2013 at 17:58 Comment(1)
Thanks for posting a solution. I had done this same fix in my local code and forgotten about this questionSkim

© 2022 - 2024 — McMap. All rights reserved.