Microsoft Office Tutorials and References
In Depth Information
User-Defined Functions (UDFs)
Adding the UDF Run-Time Reference
The Excel Services run-time assembly is installed with each Complete or Stand-Alone (evaluation) type of
MOSS installation. The run-time assembly may be available as a download some day, so you might want to
search www.Microsoft.com for this. Obtain a copy of the assembly (Microsoft.Office.Excel.Server.Udf.dll)
and place it in a location where your project can access it. Ensure that the assembly is compatible with the
ECS that will ultimately host the UDF by using either a 32-bit or a 64-bit version of the assembly.
Follow these steps to add the UDF run-time reference:
1.
Add Reference to open the Add Reference dialog box.
2. Select the Browse tab in the Add Reference dialog box. Navigate to the directory that contains
the Microsoft.Office.Excel.Server.Udf.dll run-time assembly, and select the file. Click OK. The
Solution Explorer shows the run-time assembly as a reference for the xlUdf solution.
3. In Class1.cs, add a directive for the run-time assembly namespace. At the beginning of Class1.cs
add the following using statement:
using Microsoft.Office.Excel.Server.Udf
Select Project
Adding Attributes and a Method
Follow these steps to add attributes and a method:
1. In Class1.cs, add the [UdfClass] attribute to the class. Enter the following on the line
immediately preceding public class Class1:
[UdfClass]
2. Define a UDF method within Class1 . Add the following [UdfMethod] attribute to any public
UDF method being created:
[UdfMethod]
public string EchoInput(string userInput)
{
return “Input: “ + userInput;
}
The complete solution for the UDF assembly is as follows:
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Office.Excel.Server.Udf;
namespace xlUdf
{
[UdfClass]
public class Class1
{
[UdfMethod]
public string EchoInput(string userInput)
Search JabSto ::




Custom Search