context menu in Excel 2007 (C#)

467 views
Skip to first unread message

seb...@gmail.com

unread,
Jun 30, 2014, 5:42:06 PM6/30/14
to exce...@googlegroups.com
Hi,

I'm trying to add cell context menus following the example in TestCSharp.dna but I'm not familiar with the CustomUI elements and the .dna file and I can't get the context menus to appear when I right-click on a cell.

I copy-pasted the piece of sample code of TestCSharp.dna that looks like this

<CustomUI>
  <commandBars...>
    <commandBar...>
    </commandBar>
  </commandBars>
</CustomUI>

in my .dna file, but nothing happens when I right-click. For the ribbon I could get it to work by adding a ComVisible class MyRibbon deriving from ExcelRibbon in C#, and it's fine.
Should I do something similar for the context menus?

On a related subject, could somebody recommend me a good place to learn about how the content of the .dna file is connected to the C# code behind? Something that does not assume the reader to already know much about the .dna concept. For instance even though the ribbon is working now I don't understand how the C# class is connected to it and receives its looks from it. 

Regards,

Sebastien

Govert van Drimmelen

unread,
Jun 30, 2014, 6:09:11 PM6/30/14
to exce...@googlegroups.com
Hi Sebastien,

The <customUI ...> markup in the .dna file is passed to Excel as-is, and is not processed by Excel-DNA. The best information on the ribbon, and how the handlers work, can be found in the three-part article here: http://msdn.microsoft.com/en-us/library/aa338202(office.12).aspx Excel-DNA doesn't do much about the ribbon, apart from helping to load the ExcelRibbon-derived class without needing prior registration or admin access.

About the context menus: it could be that having both the ribbon markup and the Excel-DNA <CommandBars ...>markup in the .dna file does not work. Excel-DNA pick which part to use based on the Excel version, so might ignore the CommandBars part under Excel 2007+. (Though for Excel 2010+ the context menus can be customized as part of the ribbon xml.)

I'd suggest you try one of these methods for adding the context menu:
* Call ExcelCommandBarUtil.LoadCommandBars(
    <commandBar menu='Cell'>
        <button caption='New context item' enabled='true' 
                     shortcutText='CTRL+A' onAction="ShowHelloMessage"/>
      </commandBar>
    </commandBars>");

* Use the object model exposed from ExcelDna.Integration.CustomUI to add the command bar:
    var bars = ExcelCommandBarUtil.GetCommandBars();
    var contextBar = bars("Cell");
    // ... etc   adding popup and button elements.

I haven't tried the code, so write back if you get stuck and I'll try to make a working example.

-Govert
   





From: exce...@googlegroups.com [exce...@googlegroups.com] on behalf of seb...@gmail.com [seb...@gmail.com]
Sent: 30 June 2014 11:42 PM
To: exce...@googlegroups.com
Subject: [ExcelDna] context menu in Excel 2007 (C#)

--
You received this message because you are subscribed to the Google Groups "Excel-DNA" group.
To unsubscribe from this group and stop receiving emails from it, send an email to exceldna+u...@googlegroups.com.
To post to this group, send email to exce...@googlegroups.com.
Visit this group at http://groups.google.com/group/exceldna.
For more options, visit https://groups.google.com/d/optout.

seb...@gmail.com

unread,
Jul 25, 2014, 3:41:18 PM7/25/14
to exce...@googlegroups.com
Thanks for the help Govert,

I tried your first suggestion and it worked, after I changed menu='Cell' to name='Cell'. 

Sebastien
Reply all
Reply to author
Forward
0 new messages