Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't change the label on an excel ribbon

Tags:

excel-dna

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

}
like image 701
chollida Avatar asked Feb 19 '13 20:02

chollida


1 Answers

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.

like image 69
Gabriele Avatar answered Sep 27 '22 23:09

Gabriele