Microsoft Office Tutorials and References
In Depth Information
User-Defined Functions (UDFs)
array that represents the object that was passed in. One or more rows are passed in, and the same rows
are returned.
[UdfMethod]
public object[,] Return2dObjectArray(object[,] xlRange)
{
return (xlRange)
}
In Excel, you call the Return2dObjectArray method by entering the following code into cell C11. To
create the array formula, select cells C11:E15, press F2, and then press Ctrl+Shift+Enter. Excel
automatically inserts the formula between {} (curly braces). The C11:E15 range represents the cells where the
object[,] returned from Return2dObjectArray is applied. Excel evaluates the method as #NAME? .
The example noted here uses H8:J12 as the argument to pass in. After Return2dObjectArray returns,
C11:E15 contains the same values as H8:J12 .
=Return2dObjectArray(H8:J12)
Creating a UDF
This section focuses on creating an Excel Services UDF, deploying the managed UDF assembly to the
ECS, and calling the UDF methods from an Excel workbook. Here are a few prerequisites that must be
met before you get started:
Microsoft Office SharePoint Server 2007 must be available.
Excel Services must be set up and ready to load workbooks.
There must be an Excel 12 client and an ECS trusted location where at least View permissions
are set.
A Microsoft .Net Framework 2.0 development environment must be set up (The procedures
use Microsoft Visual Studio 2005.)
Creating the C# Class Library
Follow these steps to launch Visual Studio and create the C# class library:
1.
Start Visual Studio.
2.
Select File
New
Project to open the New Project dialog box.
3.
In the Project Types frame, expand the Visual C# node and select Windows. In the Templates
frame, select Class Library.
4.
In the Name field, enter xlUdf .
5.
Set the Location field to the location where you want to create the solution.
6.
Click OK to create the library. The New Project dialog box closes, and Visual Studio opens the
xlUdf solution with Class1.cs open and visible. The namespace is xlUdf.
Search JabSto ::




Custom Search