Writing your first addin with JetXLL

| 0 Comments | 0 TrackBacks
JetXLL lets you easily expose managed code as worksheet functions in Microsoft Excel. This article will walk you through the process of creating an addin which exports some worksheet functions and show you how to load this with JetXLL. We will assume that you are using Visual Studio 2008 to create the addin and that you know how to build C# projects.

  • First Open Visual Studio and create a new C# class library project.
  • Next add a reference to the JetXLL.dll assembly. Browse for where you installed this dll, or copy it into your addin project's directory and browse for it there.
  • Add a using statement for the JetByte.JetXLL namespace.
  • Add the [AddinClass] attribute to the class that was created by the new project wizard.
  • Add a public static method to the class and decorate it with the [WorksheetFunction] attribute as shown below:
  • Build your addin.
 Worksheet functions can take parameters of any of the following standard .Net types:
  • System.Boolean
  • System.Int32
  • System.DateTime
  • System.Double
  • System.String
Or arrays of any of these types, or arrays of arrays of any of these types. 

There are some other specialist types that we can also use, but we'll deal with those a little later.

Once you have built your addin you can run Excel, and have JetXLL load your addin. There are several ways to do this but the easiest is to simply copy the JetXLL.xll (or JetXLLPro.xll) file into the same directory as your addin's dll file and the JetXLL.dll file. Next create a configuration file; like the one shown here, and place that in the same directory: 


Now simply double click on the XLL file (either JetXLL.xll or JetXLLPro.xll) and Excel will start and will load your addin and your custom worksheet function is ready to use.
Create a new sheet and type =AddTwoInts(1,1) into a cell and you should see the result.

You can download the source code for this simple addin from here. You will need a copy of JetXLL to be able to build and run the code. 

No TrackBacks

TrackBack URL: http://www.jetxll.net/cgi-bin/mt/mt-tb.cgi/8

Leave a comment

Recent Entries

Optional worksheet parameters and default values
Your custom worksheet functions can take optional parameters. The users of your worksheet can then decide whether to supply them…
Integrating your addin with Excel - the function wizard
Whilst it's very easy to create a worksheet function using C# with JetXLL simply by adding the [WorksheetFunction] attribute to…
Debugging a JetXLL addin
As you saw in the previous article, it's easy to build a custom worksheet function for Excel with JetXLL. Of…