Packing the Ribbon XML

310 views
Skip to first unread message

ajwillshire

unread,
Dec 2, 2011, 10:05:54 AM12/2/11
to Excel-DNA
Hi,

I just wanted to check my understanding of something as I realise
there's quite a lot on the site about this already, notably here:
http://groups.google.com/group/exceldna/browse_thread/thread/3961b40793269f6c/47b0552134a8e1b3?lnk=gst&q=pack+ribbon#47b0552134a8e1b3

I have an add-in that I've written in VB using Visual Studio and which
generates the ribbon interface from a stand alone XML file. All of the
ribbon handlers, etc., are in the VB code. The dna file simply points
at the dll.

However, the ribbon does not load if the project is packed.

Is it possible to pack the ribbon with the rest of the project while
keeping the separate xml file? I prefer the ribbon code to be
available to edit in Visual Studio with the rest of the project than
in the dna file.

If not currently implemented, is it something which would be worth
adding to a future release of Excel-DNA? (but I don't want to
unnecessarily add to what I imagine is a fairly big to-do list).

Thanks,
Andrew

Govert van Drimmelen

unread,
Dec 3, 2011, 5:25:47 AM12/3/11
to Excel-DNA
Hi Andrew,

At the moment I think you can do the following:
Put the CustomUI parts in a separate .dna file, which you include in
your main .dna file by
<ExternalLibrary Path="MyRibbonDna.dna" Pack="true" />

You'll still need the outer <DnaLibrary> tag though. I'm not sure how
you'd add a namespace indication to allow an xml scheme to work in
that setting, which is what I presume you want to do.

Another approach, which I suspect many people use, is to embed the
ribbon xml in your add-in .dll file as a .NET resource. Then instead
of Excel-DNA magically loading the xml, you override GetCustomUI on
your ExcelRibbon-derived class, and return the string out of the
embedded resource, which you access in the normal .NET way.

Finally, implementing your suggestion an external file with just
the .xml should not be too difficult - we already have that option for
the embedded source code via a <Source Path="..." /> tag. So I'll keep
it in mind.

Regards,
Govert

On Dec 2, 5:05 pm, ajwillshire <ajwillsh...@hotmail.co.uk> wrote:
> Hi,
>
> I just wanted to check my understanding of something as I realise
> there's quite a lot on the site about this already, notably here:

>  http://groups.google.com/group/exceldna/browse_thread/thread/3961b407...

ajwillshire

unread,
Dec 6, 2011, 9:25:12 AM12/6/11
to Excel-DNA
Hi Govert,


You were right - marking it as an embedded resource works fine, with
the packing as well.

It was slightly fiddly to get it to load from there, so here's the
code I'm now using in case anyone else needs it:


Imports ExcelDna.Integration
Imports ExcelDna.Integration.CustomUI
Imports System.Xml
Imports System.IO
Imports System.Reflection.Assembly

Public Overrides Function GetCustomUI(RibbonID As String) As String

Dim xmlstream As System.IO.Stream =
GetExecutingAssembly.GetManifestResourceStream("MyAddIn.MyRibbonXml.xml")
Dim doc As New XmlDocument
Dim reader As StreamReader = New StreamReader(xmlstream)

doc.LoadXml(reader.ReadToEnd)

Return doc.InnerXml

End Function


(As usual, if anyone can see a better way then I'd be interested in
comments)

Thanks,
Andrew

> > Andrew- Hide quoted text -
>
> - Show quoted text -

Govert van Drimmelen

unread,
Dec 6, 2011, 9:39:55 AM12/6/11
to Excel-DNA
Hi Andrew,

There should be some shortcuts for getting the resource string out,
either using the ResourceManager class, or via something like
My.Resources.TheRibbonString

-Govert

ajwillshire

unread,
Dec 6, 2011, 9:57:05 AM12/6/11
to Excel-DNA
Hi,

I also tried

Public Overrides Function GetCustomUI(RibbonID As String) As
String

Dim doc As New XmlDocument

doc.LoadXml(My.Resources.ResourceManager.GetString("MyAddIn.MyRibbonXml.xml"))

Return doc.InnerXml

End Function

but I ended up getting a bunch of exceptions on the last line
although, interestingly, the ribbon code still loaded and seemed to
work, but I decided to play safe.

The way I posted earlier was the only one that I found that ran
without any issues.

Andrew

> > > - Show quoted text -- Hide quoted text -

Reply all
Reply to author
Forward
0 new messages