Hi Simon,
Sorry - my mistake above. There is no such thing as
'ExternalReference'.
In the reply it should have been <ExternalLibrary>. I discuss
<Reference> below, but that's not really relevant to the Ribbon
issues.
Excel-DNA exports types from:
1. Code as text in .dna files. These may be one or more <Project>
tags, each compiled at runtime to an assembly, or just code,
implicitly placed in its own <Project>.
2. Code referenced in pre-compiled assemblies (.dlls).
In a .dna file you can
1. Put some code directly, or in <Project> tags, and/or
2. Export a pre-compiled assembly using <ExternalLibrary>, and/or
3. Export (recursively) the stuff from another .dna file - this can
again be code, or further <ExternalLibrary>s.
(So a .dna file can have many <ExternalLibrary> tags (with .dlls or
further .dna files), and also have many <Project> tabs with code in.)
Each assembly is processed relative to a .dna file:
1. Pre-compiled .dll assemblies are processed relative to the .dna
file where the <ExternalLibrary> tag appeared.
2. Source code in .dna files are processed relative to the .dna file
where the source code is defined.
When an assembly has an ExcelRibbon-derived class, the class is loaded
into Excel as a COM add-in. The base implementation of GetCustomUI
which returns the xml string to Excel looks for an appropriate
<CustomUI>. tag in the .dna file _that the assembly is relative to_.
You can override the GetCustomUI call and do anything else you want.
This means you can have the following layout:
1. Suppose you have RootLibrary.xll and RootLibrary.dna containing
<DnaLibrary>
<ExternalLibrary Path="MyRibbonStuff.dna" />
<ExternalLibrary Path="SomeFunctions.dll" />
</DnaLibrary>
2. and you have MyRibbonStuff.dna with
<DnaLibrary>
<ExternalLibrary Path="RibbonHandlers.dll"/>
<CustomUI>
<customUI> .... Ribbon definition ....
</customUI
</CustomUI>
</DnaLibrary>
Then the ExcelRibbon-derived class in RibbonHandlers.dll will by
default use the customUI from MyRibbonStuff.dna.
You need to be quite careful with the <CustomUI> <customUI> nesting
there - I was a bit careless when setting this up.
The outer <CustomUI> is an Excel-DNA tag, and you can have one or more
of these under a <DnaLibrary>. Inside the <CustomUI> you have the
exact string that should be passed to Excel, this starts with
<customUI xmlns=.....>
One common implementation I've seen is to put the ribbon .xml into
your assembly as a resource, and override the ExcelRibbon.GetCustomUI
to return the string from the resource. That keeps the ribbon xml
string and the .dll with the handlers together. That works perfectly
with Excel-DNA too.
My starting point was testing all of it with the handler code defined
source in the .dna file. And since the .dna file is already .xml, it
made sense to have the ribbon stuff there too.
About <Reference> tags: These are used:
1. When there is code in a .dna file to compile, these are used as
Tools->References for the compiled projects.
2. When an assembly is loaded (from .dna file or from pre-
compiled .dll), the Assembly References must be resolved. <Reference>
tags allow this resolution to occur relative to the location of the
add-in, rather than only from the GAC or relative to the location of
the Excel.exe.
3. When packing, the <Reference> assemblies with Pack='true' are also
packed, and resolved at runtime when needed like 1. or 2. above.
(Libraries in <Reference> tags are not exported to Excel as add-ins
themselves. They are for use from the ExternalLibrary or .dna source
based assemblies which define add-ins.)
If you have more questions, or any of this does not agree with your
experience, please let me know.
Also, if you can think of how it could be better designed without
giving up flexibility, I'd welcome your thoughts.
Regards,
Govert
On Jun 29, 11:35 am, Simon <
simon.mi...@solution7.co.uk> wrote:
> Hi Govert,
>
> I have a couple of questions...
>
> 1. What is the difference betweenExternalReferenceand
> ExternalLibrary?
>
> I have used <ExternalLibrary Path="MyDLL.dll"> to succesfully
> reference a .dll with my ExcelRibbon-derived class. You mention I
> should be usingExternalReference, which I can't get to work. Do you
> have an example?
>
> 2. I am a little confused by your response regarding where the ribbon
> XML should sit. From my experiments, I can only get the ribbon XML
> working in a root .dna file regardless of any ExternalLibrary
> settings. I have tried a number of combinations of ExternalLibrary
> settings to both .dna and .dll files without success.
>
> I'm not sure what you mean by '_that_ .dna file'. Are you saying that
> the ribbon XML must exist in a .dna file that contains a reference to
> the .dll file that has the ExcelRibbon-derived class? If this is the
> case, then I have not been able to get this to work successfully.
> This could, though, be down to my confusion overExternalReferenceand
> ExternalLibrary.
>
> Simon.
>
> On Jun 25, 5:44 pm, Govert van Drimmelen <
gov...@icon.co.za> wrote:
>
>
>
>
>
>
>
> > Hi Simon,
>
> > Your ExcelRibbon-derived class might be in a .dna file as text, or in
> > a .dll referenced from a .dna file usingExternalReference. The .xml