Microsoft Office Tutorials and References
In Depth Information
User-Defined Functions (UDFs)
“en-US”,
out status);
service.CalculateWorkbook(sessionId, CalculateType.CalculateFull);
byte[] savedWorkbook = service.GetWorkbook(
sessionId,
WorkbookType.FullWorkbook,
out status);
service.CloseWorkbook(sessionId);
// Save the workbook to the destination folder
string newFileName = Path.Combine(DestinationDirectory, e.Name);
BinaryWriter writer = new BinaryWriter(File.Open(
newFileName,
FileMode.CreateNew));
writer.Write(savedWorkbook);
writer.Close();
}
}
}
This sample is very rudimentary. In a real-world application, additional functionality is needed to provide
notifications or SharePoint alerts as steps in the process are completed. In addition, such a real-world
application sends multiple requests in parallel to Excel Services. The formula for calculating the number of
parallel requests is the number of ECS machines available in the farm multiplied by the number of processors
on each ECS machine.
User-Defined Functions (UDFs)
Excel Services UDFs represent another tier in the Excel Services capability to support custom solutions.
UDFs provide a means to call custom-managed code functions from within a workbook. Without UDFs,
a workbook is restricted to using only the intrinsic Excel functions. With UDFs, custom functions can be
called from the workbook as well.
UDFs are very instrumental to custom server solutions because Excel Services does not support loading
workbooks that contain code behind (VBA). Nor does Excel Services support the Excel client add-ins
used by workbooks to extend functionality. With the right UDF-managed wrapper solution, you could
leverage existing custom client solutions on the server, but that topic isn’t discussed here.
This section describes how to author managed UDFs and deploy them to the server to make them
available to workbooks that are loaded from the trusted file locations. An example solution is provided to
demonstrate the authoring and building of a UDF assembly. Additional material is provided to explain
how the workbook interacts with UDF methods, and how to pass and return arguments to the workbook.
UdfMethodAttribute Class
Each public method in the public UDF class must have the [UdfMethod] attribute if the UDF is to be
treated as a public UDF. The UdfMethodAttribute has two Boolean properties: IsVolatile and
ReturnsPersonalInformation.
Search JabSto ::




Custom Search