Excel-DNA

This is an open source project that lets you create native (.xll) add-ins for Excel using C#, VB.Net or F#.
The advantage of an XLL add-in is that it can contain high performance user-defined functions, custom ribbon interfaces plus more and requires no installation or registration and therefore working in reduced privilege environments.
The C API is not directly accessible from .NET code but the Excel-DNA runtime allows managed assemblies to integrate with the C API.


Worksheet Functions

You are able to define the function wizard category as well as the function description and argument descriptions.
In Excel-DNA this is made possible by adding .NET attributes to the function declarations.


Other Supported Features

Multi-threaded recalculation
RTD Servers
Custom Task Panes
Integration with VBA code


The Excel-DNA runtime contains a small loader (the .XLL) that loads the .NET runtime, then checks the configuration (.dna) file and accordingly loads the managed assembly.
The managed assemblies are then inspected using the .NET Reflection API and the appropriate methods are registered.


Create Basic Add-in

This consists of three files:
1) The managed assembly MyCSharpCode.dll
2) The Excel-DNA runtime library. Distributed as exceldna.xll but renamed to MyFirstAddin.xll
3) A configuration file which is a text-based XML file renamed to MyFirstAddin.dna which contains the following:


<DnaLibrary Name="My First AddIn" RuntimeVersion="v4.0" > 
   <ExternalLibrary Path="MyCSharpCode.dll"/>
</DnaLibrary


using ExcelDna.Integration 

namespace MyNewXLL
{
   public class MyClass
   {
      [ExcelFunction(Description="HelloWorld")]
      public static string MyFunction([ExcelArgument(Description=@"Text Value")] string sText)
      {
         return sText + sText;
      }
   }
}


AutoOpen and AutoClose

These methods will be called when your add-in is loaded and unloaded from the Excel Add-ins dialog box

public void AutoOpen() 
{}
public void AutoClose()
{}



Single File

Excel-DNA also contains a special packing feature that allows you to create a single xll file containing all the necessary files.



Resources

github.com/Excel-DNA
exceldna.codeplex.com


© 2017 Better Solutions Limited. All Rights Reserved. © 2017 Better Solutions Limited

Top

PrevNext