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.
This consists of three files: a config file, a managed assembly and the exceldna.xll (which can be renamed)
Supported Features - Multi-threaded recalculation, Custom Ribbon Interfaces, RTD Servers, Custom Task Panes
exceldna.codeplex.com/
excel-dna.net/
github.com/Excel-DNA
Has a NuGet Package
Worksheet Functions
You are able to define the function wizard category as well as the function description and argument descriptions.
You can set the function wizard category as well as the function and argument descriptions.
You can even provide a tooltip
These customisations can be made by adding .NET attributes to the function declarations.
Supports two types of async functions
RTD Based Async
Uses ExcelAsyncUtil
Can interact with Excel while the function executes
This uses an internal RTD server internally
Native Async
Only works with Excel 2010 or later
Cannot interact with Excel while the function executes
Can continue with other parts of the calculation tree while the function executes.
ExcelAsyncUtil
Run -
Initialize -
UnInitialize -
Observe -
QueueMacro - waits for the main Excel thread to be free and then runs the corresponding code
AutoOpen -
AutoClose -
Configuration File
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
Managed Assembly
These methods will be called when your add-in is loaded and unloaded from the Excel Add-ins dialog box
using ExcelDna.Integration
namespace MyNewXLL
{
public class MyAddin : ExcelDna.Integration.IExcelAddIn
{
public void AutoOpen()
{
}
public void AutoClose()
{
}
[ExcelFunction(Description="HelloWorld", Name="myFunction")]
public static string MyFunction([ExcelArgument(Description=@"Text Value")] string sText)
{
return sText + sText;
}
private static void Method_Helper()
{
}
}
< DnaLibrary Name="MyXLL"
RuntimeVersion="v4.0"
Language="C#" <
< ExternalLibrary Path="MyXLL.dll"
LoadFromBytes = false
Pack = "true" <
Need to add a registry key
HKCU\Software\Microsoft\Office\12.0\Excel\Options\ OPEN1 - /R "MyXLL.dll"
If the add-in is not in the default add-ins folder then the full path must be provided
Search for OPEN[n] key
Use a custom action to loop through the keys
Does it need to be shimmed ?
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.
Single File
Excel-DNA also contains a special packing feature that allows you to create a single xll file containing all the necessary files.
ExcelDna.Integration.XlCall.Excel
ExcelDna.Integration.XlCall.Excel
ExcelDna.Integration.XlCall.Excel
© 2021 Better Solutions Limited. All Rights Reserved. © 2021 Better Solutions Limited TopPrevNext