<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
    <title>JetXLL</title>
    <link rel="alternate" type="text/html" href="http://www.jetxll.net/" />
    <link rel="self" type="application/atom+xml" href="http://www.jetxll.net/atom.xml" />
    <id>tag:www.jetxll.net,2009-07-30://2</id>
    <updated>2009-10-01T08:06:16Z</updated>
    <subtitle>The easy and affordable way for everyone to build custom worksheet functions for Microsoft Excel. </subtitle>
    <generator uri="http://www.sixapart.com/movabletype/">Movable Type Pro 4.3-en</generator>

<entry>
    <title>Optional worksheet parameters and default values</title>
    <link rel="alternate" type="text/html" href="http://www.jetxll.net/2009/10/optional-worksheet-parameters-and-default-values.html" />
    <id>tag:www.jetxll.com,2009://2.20</id>

    <published>2009-10-01T07:15:00Z</published>
    <updated>2009-10-01T08:06:16Z</updated>

    <summary>Your custom worksheet functions can take optional parameters. The users of your worksheet can then decide whether to supply them or leave them blank. Optional parameters can be indicated in one of two ways, as with parameter help strings that...</summary>
    <author>
        <name>Len</name>
        <uri>http://www.lenholgate.com</uri>
    </author>
    
        <category term="How to" scheme="http://www.sixapart.com/ns/types#category" />
    
        <category term="JetXLL" scheme="http://www.sixapart.com/ns/types#category" />
    
        <category term="JetXLLPro" scheme="http://www.sixapart.com/ns/types#category" />
    
    <category term="default" label="default" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="jetxll" label="JetXLL" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="managedxlls" label="managed XLLs" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="optional" label="optional" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en-us" xml:base="http://www.jetxll.net/">
        <![CDATA[Your custom worksheet functions can take optional parameters. The users of your worksheet can then decide whether to supply them or leave them blank. Optional parameters can be indicated in one of two ways, as with parameter help strings that were explained in a <a href="http://www.jetxll.com/2009/09/integrating-your-addin-with-excel---the-function-wizard.html">previous article</a>.<div><br />
<textarea name="code" class="c#:nocontrols:nogutter" cols="60" rows="8">
      [WorksheetFunction]
      public int TakesAnOptionalInt(
         int a,
         [Optional] int b)
      {
         return a + b;
      }
</textarea><div><br /></div>
Either using the <b>[Optional]</b> attribute, as shown above. Or by using the <b>IsOptional</b> parameter of the <b>[ParameterDetails]</b> attribute as shown below.<div><br /><div><textarea name="code" class="c#:nocontrols:nogutter" cols="60" rows="9">
      [WorksheetFunction]
      [ParameterDetails(Name = "b", IsOptional = true)]
      public int TakesAnOptionalInt3(
         int a,
         int b)
      {
         return a + b;
      }
</textarea><div><br /></div></div></div></div>
If an optional parameter is not supplied to the worksheet function then you get passed a zero value for all numeric types and an empty string for string types. Sometimes you may wish to provide your own default value for a missing optional parameter. In that case you can use the <b>[DefaultValue]</b> attribute or the <b>DefaultValue</b> parameter to the <b>[ParameterDetails]</b> attribute. See below:<div><br /><div><textarea name="code" class="c#:nocontrols:nogutter" cols="60" rows="17">
      [WorksheetFunction]
      private int HasADefaultValue(
         int a,
         [DefaultValue(666)] int b)
      {
         return a + b;
      }

      [WorksheetFunction]
      [ParameterDetails(Name = "b", DefaultValue=666)]
      private int HasADefaultValue2(
         int a,
         int b)
      {
         return a + b;
      }
</textarea><div><br /></div>
Default values can also be supplied for array parameters, see below:</div><div><br /></div></div>
<textarea name="code" class="c#:nocontrols:nogutter" cols="60" rows="31">
      [WorksheetFunction]
      private int TakesDefaultArray(
         int a,
         [DefaultValue(new int[] { 1, 2, 3, 4 })] int[] b)
      {
         int result = 0;
 
         foreach (int i in b)
         {
            result += (a * i);
         }

         return result;
      }

      [WorksheetFunction]
      [ParameterDetails(Name = "b", DefaultValue = new int[] { 1, 2, 3, 4 })]
      private int TakesDefaultArray2(
         int a,
         int[] b)
      {
         int result = 0;

         foreach (int i in b)
         {
            result += (a * i);
         }

         return result;
      }
</textarea><div><br /></div>

Finally, you may prefer to indicate to your users which parameters are optional and which are not, you can do this by setting the&nbsp;<b>OptionalParameterEmbelishment</b> parameter of the <b>[AddinClass]</b> attribute to&nbsp;<b>UseSquareBrackets</b> which causes all optional parameters to be displayed in the function wizard within square brackets.<div>&nbsp;<div><textarea name="code" class="c#:nocontrols:nogutter" cols="60" rows="13">
   [AddinClass(OptionalParameterEmbelishment = OptionalParameterEmbelishment.UseSquareBrackets)]
   [ExcelCategory("Optional Parameters")]
   class Class2
   {
      [WorksheetFunction]
      public int TakesAnOptionalInt2(
         int a,
         [Optional] int b)
      {
         return a + b;
      }
   }
</textarea></div><div><font class="Apple-style-span" color="#000000" face="monospace"><span class="Apple-style-span" style="white-space: pre-wrap;"><br /></span></font></div></div>

You can download the source code for this example code from <a href="http://www.jetxll.net/ExampleCode/OptionalParametersAndDefaultValues.zip">here</a>. You will need a copy of JetXLL to be able to build and run the code. ]]>
        
    </content>
</entry>

<entry>
    <title>Integrating your addin with Excel - the function wizard</title>
    <link rel="alternate" type="text/html" href="http://www.jetxll.net/2009/09/integrating-your-addin-with-excel---the-function-wizard.html" />
    <id>tag:www.jetxll.com,2009://2.19</id>

    <published>2009-09-30T15:14:38Z</published>
    <updated>2009-10-01T08:05:32Z</updated>

    <summary>Whilst it&apos;s very easy to create a worksheet function using C# with JetXLL simply by adding the [WorksheetFunction] attribute to your code you can add additional attributes and set some parameters on the [WorksheetFunction] attribute to allow your code to...</summary>
    <author>
        <name>Len</name>
        <uri>http://www.lenholgate.com</uri>
    </author>
    
        <category term="How to" scheme="http://www.sixapart.com/ns/types#category" />
    
        <category term="JetXLL" scheme="http://www.sixapart.com/ns/types#category" />
    
        <category term="JetXLLPro" scheme="http://www.sixapart.com/ns/types#category" />
    
    <category term="functionwizard" label="Function Wizard" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="jetxll" label="JetXLL" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="managedxlls" label="managed XLLs" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en-us" xml:base="http://www.jetxll.net/">
        <![CDATA[Whilst it's <a href="http://www.jetxll.com/2009/09/writing-your-first-addin-with-jetxll.html">very easy to create a worksheet function</a> using C# with JetXLL simply by adding the <b>[WorksheetFunction]</b> attribute to your code you can add additional attributes and set some parameters on the <b>[WorksheetFunction]</b> attribute to allow your code to integrate better with Excel. This article will explain how you can make your worksheet function integrate nicely with the Excel Function Wizard.<div><br /><div><img alt="ExcelFunctionWizard.png" src="http://www.jetxll.com/ExcelFunctionWizard.png" width="276" height="287" class="mt-image-right" style="float: right; margin: 0 0 20px 20px;" /></div><div>The function wizard provides help for you whilst you are inserting a function into a cell. The simple addin we built in the <a href="http://www.jetxll.com/2009/09/writing-your-first-addin-with-jetxll.html">previous article</a> can be accessed from the function wizard like any other but the user experience can be made better by adjusting the attributes that you apply to your code.</div><div><br /></div><div>The first way that you can integrate with the function wizard is by placing your functions in your own categories; or, if it's appropriate, by adding them to existing categories.&nbsp;</div><div><br /></div><div>By default a <b>JetXLL </b>worksheet function is placed in a function wizard category that consists of "<b>JetXLL: </b>" followed by the name of the class in which the function was defined. So, our AddTwoInts() function in the SimpleAddin will be in the category "<b>JetXLL: SimpleAddin</b>".&nbsp;</div><div><br /></div><div>You can select the category that your worksheet functions appear in by applying the <b>[ExcelCategory]</b> attribute either at the class level, so that it applies to all worksheet functions within that class, or at the function level. If you apply the attribute at the class level then you can override it at the function level if you need to.</div><div><br /></div><div>The <b>[ExcelCategory]</b> attribute takes a parameter to indicate the category to place the functions in. This is either a member of the&nbsp;<b>StandardExcelCategory</b> enumeration; such as "Database", "Information", "Logical", etc or a string which is the name of your own custom category. See the example below for more details.</div></div>
<textarea name="code" class="c#:nocontrols:nogutter" cols="60" rows="36">
using JetByte.JetXLL;

namespace FunctionWizardIntegration
{
   [AddinClass]
   [ExcelCategory(StandardExcelCategory.Information)]
   public class Class1
   {
      [WorksheetFunction]
      static public int UsesTheClassLevelCategory(
         int a,
         int b)
      {
         return a + b;
      }

      [WorksheetFunction]
      [ExcelCategory(StandardExcelCategory.Financial)]
      static public int BelongsToAStandardCategory(
         int a,
         int b)
      {
         return a + b;
      }

      [WorksheetFunction]
      [ExcelCategory("Has its own category")]
      private int HasItsOwnCategory(
         int a,
         int b)
      {
         return a + b;
      }
   }
}
</textarea>
<br />
Note that you can create multiple addins and place functions from different addins into the same custom categories. The custom names are not unique between addins, or even to <b>JetXLL</b> addins.&nbsp;<div><br />
Once you've placed your custom worksheet functions in appropriate categories you might wish to give your users a little more help whilst they are selecting their functions.&nbsp;</div><div><br /><div><font class="Apple-style-span" color="#000000" face="monospace"><span class="Apple-style-span" style="white-space: pre-wrap;"><img alt="ExcelFunctionWizardFunctionArgumentHelp.png" src="http://www.jetxll.com/ExcelFunctionWizardFunctionArgumentHelp.png" width="537" height="344" class="mt-image-center" style="text-align: center; display: block; margin: 0 auto 20px;" /></span></font></div><div>We can add these help strings for our own functions. First we can add a function help string, this is the string that reads "Returns the accrued..." in the dialog above. We do this by adding a <b>HelpString</b> parameter to the <b>[WorkSheetFunction]</b> attribute. Next we can add individual help strings for each parameter. There are two ways to do this, both are equivalent and the choice of which method to use is purely based on the&nbsp;aesthetics&nbsp;of &nbsp;the resulting code; some people prefer the look of one method over the other.</div><div><br /></div><div>The first method is to add <b>[HelpString]</b> attributes to each parameter as shown below:</div>
<textarea name="code" class="c#:nocontrols:nogutter" cols="60" rows="9">
      [WorksheetFunction]
      [ExcelCategory(StandardExcelCategory.Financial)]
      static public int BelongsToAStandardCategory(
         [HelpString("This is the help string for parameter a")] int a,
         [HelpString("This is the help string for parameter b")] int b)
      {
         return a + b;
      }
</textarea>
<br />The second is to use the <b>[ParameterDetails]</b> attribute at the function level as shown below:<div><br /></div>
<textarea name="code" class="c#:nocontrols:nogutter" cols="60" rows="13">
      [WorksheetFunction(HelpString="This is a function which has its own category and adds two numbers")]
      [ExcelCategory("Has its own category")]
      [ParameterDetails(Name="a", HelpString="This is the help string for parameter a")]
      [ParameterDetails(Name = "b", NameAs="The second", HelpString = "This is the help string for parameter b")]
      private int HasItsOwnCategory(
         int a,
         int b)
      {
         return a + b;
      }
</textarea>
<br />
As you can see, using the <b>[ParameterDetails]</b> attribute keeps the parameters themselves uncluttered; some users prefer this style. Since all of the parameter details attributes for all of the parameters appear together they need to contain the name of the parameter that they are affecting; the <b>Name</b> parameter serves this purpose. Note that you can provide parameter details for all or just for some parameters and that if a parameter has both a <b>[ParameterDetails]</b> attribute and a parameter level <b>[HelpString]</b> attribute applied to it then the parameter level attribute takes precedence.<div><br /></div><div>As you can see from the example above, the parameter name that is exposed to Excel need not be the same as the variable name in the function declaration itself. Once again there are two methods of changing this name. The first is by using the <b>NameAs</b> parameter of the <b>[ParameterDetails]</b> attribute as shown above. The second is to apply a <b>[NameAs]</b> attribute at the parameter level as shown below:<br /></div>
<textarea name="code" class="c#:nocontrols:nogutter" cols="60" rows="8">
      [WorksheetFunction]
      static public int UsesTheClassLevelCategory(
         [NameAs("First value")] int a,
         [NameAs("second value")]int b)
      {
         return a + b;
      }
</textarea>
<br />One thing to note from the code example above is that by default all parameter names have the first letter capitalised. That is, in the function wizard, the second parameter will be referred to as "Second value" rather than "second value". This is so that for normal code, without any parameter naming attributes, <b>JetXLL</b> will make the parameters look similar to how most other Excel function parameters look. You can change this behaviour by setting the <b>ParameterEmbelishment</b> value of the <b>[AddinClass]</b> attribute to <b>NoEmbelishment</b>.<div><br /></div><div>By default <b>JetXLL</b> does not call your worksheet functions when the Excel function wizard is active. This is because in most situations you don't want your functions called when the user is using the wizard to enter parameter values. All of the values may not be present and the work that your custom worksheet function performs may require all parameters and may be costly to perform. You can change this with the <b>CallWhenFunctionWizardIsActive</b> parameter of the <b>[WorksheetFunction]</b> attribute. See the following code example:</div>
<textarea name="code" class="c#:nocontrols:nogutter" cols="60" rows="19">
      [WorksheetFunction(
         HelpString = "Adds a series of numbers together",
         CallWhenFunctionWizardIsActive = true)]
      static public int CalledWhenFunctionWizardIsActive(
         int a1,
         [Optional] int a2,
         [Optional] int a3,
         [Optional] int a4,
         [Optional] int a5,
         [Optional] int a6,
         [Optional] int a7,
         [Optional] int a8,
         [Optional] int a9,
         [Optional] int a10)
      {
         return a1 + a2 + a3 + a4 + a5 + a6 + a7 + a8 + a9 + a10;
      }
</textarea>
<br />As you enter each of the optional values in the function wizard you'll see the result of the calculation so far. It's not often that this technique is required and it's more efficient to leave the default setting of '<b>false</b>' for<b>&nbsp;CallWhenFunctionWizardIsActive.</b><div><br /></div><div>As you can see it's easy to add attributes to your code so that your functions are easier to use by your users and look more like built in Excel functions.&nbsp;</div><div><br /></div><div>You can download the source code for this example code from&nbsp;<a href="http://www.jetxll.net/ExampleCode/FunctionWizardIntegration.zip" style="text-decoration: underline; ">here</a>. You will need a copy of&nbsp;<b>JetXLL</b>&nbsp;to be able to build and run the code.&nbsp;</div></div>]]>
        
    </content>
</entry>

<entry>
    <title>Debugging a JetXLL addin</title>
    <link rel="alternate" type="text/html" href="http://www.jetxll.net/2009/09/debugging-a-jetxll-addin.html" />
    <id>tag:www.jetxll.com,2009://2.18</id>

    <published>2009-09-30T10:55:14Z</published>
    <updated>2009-09-30T11:10:18Z</updated>

    <summary>As you saw in the previous article, it&apos;s easy to build a custom worksheet function for Excel with JetXLL. Of course, whilst you are developing your worksheet functions you may make mistakes and wish to debug the code whilst it...</summary>
    <author>
        <name>Len</name>
        <uri>http://www.lenholgate.com</uri>
    </author>
    
        <category term="Debugging" scheme="http://www.sixapart.com/ns/types#category" />
    
        <category term="How to" scheme="http://www.sixapart.com/ns/types#category" />
    
        <category term="JetXLL" scheme="http://www.sixapart.com/ns/types#category" />
    
        <category term="JetXLLPro" scheme="http://www.sixapart.com/ns/types#category" />
    
    <category term="debugging" label="Debugging" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="howto" label="HowTo" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="jetxll" label="JetXLL" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="managedxlls" label="managed XLLs" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en-us" xml:base="http://www.jetxll.net/">
        <![CDATA[As you saw in the <a href="http://www.jetxll.com/2009/09/writing-your-first-addin-with-jetxll.html">previous article</a>, it's easy to build a custom worksheet function for Excel with <b>JetXLL</b>. Of course, whilst you are developing your worksheet functions you may make mistakes and wish to debug the code whilst it is running inside Excel; luckily this too is very easy!<div><br /><div><ul><li>Open the SimpleAddin solution file, select the solution explorer tab and select the solution.</li><li>Right click and select properties.</li><li>Select the Debug tab and check the 'start external program' button.</li><li>Browse for the Excel executable (usually located at Program Files\Microsoft Office\Office12\Excel.exe).</li><li>Build the addin and copy the JetXLL.xll file and JetXLL.xml file into the same directory as the addin's dll file that you have just built.</li><li>Start debugging and Excel will start up; you may get a warning about Excel not containing debugging information, you can ignore this.</li><li>Place a breakpoint in your addin.</li><li>Within Excel select File, Open and browse to the directory where you built your addin, select the JetXLL.xll file and open it. This will load <b>JetXLL</b> and your addin into Excel.</li><li>Enter your worksheet function into a cell and when the cell is calculated you will find yourself in the debugger inside your worksheet function.</li></ul><div>You may want to set up Excel so that you always load <b>JetXLL</b> and your addins, a future article will show you how to do this. If you set Excel up in this way then debugging is even easier, as soon as Excel is loaded by the debugger it will load <b>JetXLL</b> and your addin and you can simply load a test sheet and step into your functions.</div></div><div><div><br /></div><div><br /></div></div></div>]]>
        
    </content>
</entry>

<entry>
    <title>Writing your first addin with JetXLL</title>
    <link rel="alternate" type="text/html" href="http://www.jetxll.net/2009/09/writing-your-first-addin-with-jetxll.html" />
    <id>tag:www.jetxll.com,2009://2.17</id>

    <published>2009-09-30T09:09:38Z</published>
    <updated>2009-09-30T10:54:38Z</updated>

    <summary>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...</summary>
    <author>
        <name>Len</name>
        <uri>http://www.lenholgate.com</uri>
    </author>
    
        <category term="How to" scheme="http://www.sixapart.com/ns/types#category" />
    
        <category term="JetXLL" scheme="http://www.sixapart.com/ns/types#category" />
    
        <category term="JetXLLPro" scheme="http://www.sixapart.com/ns/types#category" />
    
    <category term="howto" label="HowTo" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="jetxll" label="JetXLL" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="managedxlls" label="managed XLLs" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en-us" xml:base="http://www.jetxll.net/">
        <![CDATA[<b>JetXLL</b> 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 <b>JetXLL</b>. We will assume that you are using Visual Studio 2008 to create the addin and that you know how to build C# projects.<div><br /></div><div><ul><li>First Open Visual Studio and create a new C# class library project.</li><li>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.</li><li>Add a using statement for the <b>JetByte.JetXLL</b> namespace.</li><li>Add the <b>[AddinClass]</b> attribute to the class that was created by the new project wizard.</li><li>Add a public static method to the class and decorate it with the <b>[WorksheetFunction]</b> attribute as shown below:</li></ul></div>
<textarea name="code" class="c#:nocontrols:nogutter" cols="60" rows="17">
using JetByte.JetXLL;

namespace SimpleAddin
{
   [AddinClass]
   public class Class1
   {
      [WorksheetFunction]
      static public int AddTwoInts(
         int a,
         int b)
      {
         return a + b;
      }
   }
}
</textarea>
<ul><li>Build your addin.</li></ul>
&nbsp;Worksheet functions can take parameters of any of the following standard .Net types:
<br />
<ul>
<li>System.Boolean</li>
<li>System.Int32</li>
<li>System.DateTime</li>
<li>System.Double</li>
<li>System.String</li>
</ul>
Or arrays of any of these types, or arrays of arrays of any of these types.&nbsp;<div><br />
There are some other specialist types that we can also use, but we'll deal with those a little later.</div><div><br /></div><div>Once you have built your addin you can run Excel, and have <b>JetXLL</b> 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:&nbsp;</div><div><br /></div>
<textarea name="code" class="xml:nocontrols:nogutter" cols="60" rows="7">
<?xml version="1.0" encoding="Windows-1252"?>
<Configuration>
  <Addins>
    <Addin name="SimpleAddin"></Addin>
  </Addins>
</Configuration>
</textarea><div><br /></div>
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.
<br />
Create a new sheet and type =AddTwoInts(1,1) into a cell and you should see the result.<div><br /></div><div>You can download the source code for this simple addin from <a href="http://www.jetxll.net/ExampleCode/SimpleAddin.zip">here</a>. You will need a copy of <b>JetXLL</b> to be able to build and run the code.&nbsp;</div>]]>
        
    </content>
</entry>

<entry>
    <title>An introduction to Managed XLLs in Excel with JetXLL </title>
    <link rel="alternate" type="text/html" href="http://www.jetxll.net/2009/09/an-introduction-to-managed-xlls-in-excel-with-jetxll.html" />
    <id>tag:www.jetxll.com,2009://2.16</id>

    <published>2009-09-29T10:35:29Z</published>
    <updated>2009-09-29T14:35:15Z</updated>

    <summary>JetXLL is a quick, easy and affordable way to create custom worksheet functions and complete XLL addins for Excel using managed code (such as C#). There are plenty of other ways to do this (see the links at the end...</summary>
    <author>
        <name>Len</name>
        <uri>http://www.lenholgate.com</uri>
    </author>
    
        <category term="How to" scheme="http://www.sixapart.com/ns/types#category" />
    
        <category term="JetXLL" scheme="http://www.sixapart.com/ns/types#category" />
    
        <category term="JetXLLPro" scheme="http://www.sixapart.com/ns/types#category" />
    
    <category term="howto" label="HowTo" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="jetxll" label="JetXLL" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="managedxlls" label="managed XLLs" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en-us" xml:base="http://www.jetxll.net/">
        <![CDATA[JetXLL is a quick, easy and affordable way to create custom worksheet functions and complete XLL addins for Excel using managed code (such as C#). There are plenty of other ways to do this (see the links at the end of this article), but, we feel that JetXLL makes it very easy for people who are comfortable writing managed code to expose it&nbsp;to Excel. With JetXLL you can access functionality that Excel's 'C API' exposes without needing to understand the complexity of writing an XLL from scratch in a language such as C or C++.&nbsp;<div><div><br /></div><div>It's very easy to expose your managed code as an Excel worksheet function using JetXLL. First add a reference to the JetXLL.dll to your code and then, simply decorate the class with the <b>[AddinClass]</b> attribute and the functions that you want to expose to Excel with the <b>[WorksheetFunction]</b> attribute. Edit the JetXLL configuration file so that JetXLL will load your assembly and that's it. When the JetXLL addin is loaded it will load your assembly, parse your code for its attributes and expose your functions to Excel.</div><div><br /></div>
<textarea name="code" class="c#:nocontrols:nogutter" cols="60" rows="10">
using JetByte.JetXLL;

namespace TestAddin1
{
   [AddinClass]
   [ExcelCategory("Simple Static Functions")]
   public class SimpleStaticFunctions
   {
      static public int NotAWorksheetFunction()
      {
         return 0;
      }

      [WorksheetFunction]
      static public int AddTwoInts(
         int a,
         int b)
      {
         return a + b;
      }  
</textarea>
<div><br /></div><div>The simple example above shows how to expose a static function as an Excel worksheet function. You can now type <b>=AddTwoInts()</b> into an Excel cell and provide the two numbers that the function requires (<b>=AddTwoInts(A1, B2)</b> for example) and Excel will call your C# code and place the value that you return into the spreadsheet cell for you.</div><div><br /></div><div><img alt="AddTwoInts.png" src="http://www.jetxll.com/Blog/Pictures/AddTwoInts.png" width="297" height="239" class="mt-image-center" style="text-align: center; display: block; margin: 0 auto 20px;" /></div><div>There's much more to JetXLL, you can expose member functions and indicate which constructor that Excel should call on your classes. You can create Command Functions which can be called from menus, toolbar buttons and macros. You can build custom Excel menus or Toolbars which can call your Command functions. If you have functions that take a while to execute you can use the <b>[AsyncWorksheetFunction]</b> attribute to have JetXLL call the function on a separate thread and you can use the&nbsp;<b>IAsyncWorksheetFunctionCall</b> interface to pass back interim results which are displayed by Excel as your calculation progresses.</div><div><br /></div>
<textarea name="code" class="c#:nocontrols:nogutter" cols="60" rows="10">
      [AsyncWorksheetFunction]
      static public int AsyncWorksheetFunction2(
         [DefaultValue(10000)] int delay,
         IAsyncWorksheetFunctionCall call)
      {
         for (int i = 0; i < delay; ++i)
         {
            Thread.Sleep(1);

            if (call.BreakRequested())
            {
               break;
            }

            if (i % 100 == 0)
            {
               call.ReturnInterimResult(i);
            }
         }

         numCalls2++;

         return numCalls2;
      }
</textarea>
<div><br /></div><div>If you need to push Real Time Data into your Excel spreadsheets then you can use JetXLL's RTD support to implement a data source without the need to register any COM objects on your workstation and without needing to understand the complexity of the Excel RTD API.</div>
<textarea name="code" class="c#:nocontrols:nogutter" cols="60" rows="10">
      [RealTimeDataStartFunction]
      public void Start(
         IRealTimeDataCallback callback)
      {
         this.callback = callback;

         thread = new Thread(ThreadFunction);

         thread.Start(this);
      }

      [RealTimeDataConnectFunction]
      public string Connect(
         int topicId,
         string[] topic,
         bool getNewValues)
      {
         if (getNewValues)
         {
            return Refresh(topicId);
         }

         return "";
      }

      // refresh single topic (called for all updated topics)

      [RealTimeDataRefreshFunction]
      public string Refresh(
         int topicId)
      {
         return "Topic: " + topicId + " " + DateTime.Now.ToLongTimeString();
      }

      [RealTimeDataDisconnectFunction]
      public void Disconnect(
         int topicId)
      {

      }

      [RealTimeDataStopFunction]
      public void Stop()
      {
         stopEvent.Set();
      }
</textarea><div><br /></div>Managed code can return 'results objects' to Excel which can be passed by name to other JetXLL functions and which can be queried and manipulated within the sheet.&nbsp;</div><div><br /></div><div><textarea name="code" class="c#:nocontrols:nogutter" cols="60" rows="10">
      [WorksheetFunction(IsVolatile = true, IsThreadSafe = true)]
      [ResultsObject(IsOptional = true)]
      static public int ReturnResultsObject2(
         int a,
         int b)
      {
         return a + b;
      }

</textarea><div><br /></div><div>JetXLL provides direct support for "trigger" arguments to Excel worksheet functions. Trigger arguments are dummy arguments that are passed to worksheet functions purely to trigger them (by providing an otherwise impossible dependency to another part of the sheet), they can also be used to prevent 'expensive' calls&nbsp;being made whilst you are configuring the worksheet, or to allow you to 'turn off' aeas of the worksheet using a single trigger cell which can be set to <b>FALSE</b>. Trigger arguments are supported by JetXLL in such a way that they can be automatically&nbsp;added to a managed functions worksheet function signature and then managed completely&nbsp;by JetXLL. Your managed code is never called and marshalling of additional arguments is not done if the trigger argument evaluates to <b>FALSE</b>.</div><div><div><br /></div><div>This worksheet function takes an implicit trigger argument. By default the name of the&nbsp;argument is 'Trigger', the help string is 'Trigger the function call if TRUE' and the&nbsp;message returned if the call is not made is 'Call not made'. All of these are configurable. If the optional trigger argument is not <b>TRUE</b> then the call is not made.</div>
<textarea name="code" class="c#:nocontrols:nogutter" cols="60" rows="10">
      [WorksheetFunction(IsThreadSafe = true)]
      [Trigger]                                   
      static public int TakesTriggerArgument()     
      {                                            
         return 5;                                 
      }
</textarea>
<div><br /></div><div>JetXLL is currently in a beta testing phase. If you'd like to be involved with the beta test and try out JetXLL during this time then please get in touch with us by emailing us at <b>beta (at) jetxll.net</b>.</div><div><br /></div></div><div>Some alternative ways to create managed XLLs</div><div><ul><li><a href="http://www.managedxll.com/">Stochastix Managed XLL</a>.&nbsp;</li><li><a href="http://www.add-in-express.com/">Add-in Express</a>.</li><li><a href="http://exceldna.typepad.com/blog/">ExcelDNA</a>.</li><li><a href="http://excel4net.blogspot.com/">Excel4Net</a>.</li><li><a href="http://xlw.sourceforge.net/">XLW</a>.</li><li><a href="http://www.planatechsolutions.com">XLL Plus</a>.</li></ul><div>Alternatively you might want to take a look at <a href="http://msdn.microsoft.com/en-us/vsto/default.aspx">Visual Studio Tools for Office</a> (VSTO).</div></div></div>]]>
        
    </content>
</entry>

</feed>
