If you use the Import Editor
to control the import of methods from your assembly,
your settings are saved in an instruction file,
[assembly-name].dll.xnr
.
The settings are read in by the import tool when the application is built.
As an alternative, you can apply attributes directly to your .NET classes and methods.
You can add atributes to your .NET method to control many aspects of the function's behaviour and how the arguments are treated, including:
For example, some XLL+ import attributes have been added to the C# code below:
[XllFunction] public static string TestFunction(string a, double b, int c, bool d) { return String.Format("a={0};b={1};c={2};d={3}", a, b, c, d); } [XllFunction("AddTwoNumbers")] public static int MyAdd( [XllArgument("First", Flags=XlArgumentFlags.Optional, DefaultValue="100")] int a, [XllArgument("Second", Flags=XlArgumentFlags.Optional, DefaultValue="-99")] int b) { return a + b; }
The table below lists the main attributes:
Attribute | Description |
---|---|
XllFunction | Controls the export of a specific method or property as an Excel add-in function. |
XllArgument | Controls the export and marshalling of a single argument of an exported Excel add-in function. |
For full details see the .NET Runtime Library Reference.
To use attributes in an existing .NET library, follow these steps:
Add a reference to the XLL+ Reflection Runtime library,
Psl.XL6.XnReflect.Runtime.dll
.
This is located in the bin
subdirectory of the XLL+ installation folder.
Optionally, add a using
statement to your C# code:
Add a XllFunction
attribute to any functions that you
wish to export to Excel.
Add XllArgument
attributes to any arguments that
need special handling.
Ensure that your project generates an XML documentation file, and make sure that the comments for all exported functions are up to date.
Inspect the NetWrapAttr walkthrough for more details on how to import a .NET assembly using attributes.