by clearoffice
30. October 2009 07:19
The functions accessible from worksheet formulas are implemented as public static functions in special assemblies also called add-in.
Spreadsheet Clear Office comes with two add-ins:
- The standard add-in (Office.Spreadsheet.StandardAddIn.dll) provides ”must have” functions such as SUM, OR and LOWER
- the Analysis Toolpak add-in (Office.Spreadsheet.AnalysisToolpak.dll) contains more advanced functions such as ACCRINT, ISEVEN and PRICEDISC
By default, spreadsheet document have access only to these two add-ins but you can write your own add-in as well. The first step is create a .NET assembly with the appropriate settings. The second step is to make it accessible to spreadsheet document.
Add-in functions must verify the following:
- They must be marked as public and static.
- The containing class must be public and annotated with the [AddInFunctions] custom attribute.
Spreadsheet document discover add-ins through a SpreadsheetContext. By default, the spreadsheet context contains only the two built-in add-ins but you can create your own context with additional add-ins. If you do so, make sure you also add the built-in add-ins as well:
AddIn addIn1 = new AddIn(typeof (Office.Spreadsheet.StandardAddIn.LogicalFunctions).Assembly);
AddIn addIn2 = new AddIn(typeof (Office.Spreadsheet.AnalysisToolPak.DateFunctions).Assembly);
AddIn addIn3 = new AddIn(typeof (CustomSpreadsheetFunctions.MyFunctions).Assembly);
SpreadsheetContext context = new SpreadsheetContext(new AddIn[] {addIn1, addIn2, addIn3});
Once you have created your context, pass it to the spreadsheet document:
SpreadsheetDocument document = SpreadsheetDocument.Create(context);
Two samples demonstrate how to create and use add-ins: CustomSpreadsheetFunctions contains a custom add-in while HostCustomSpreadsheetFunctions uses this add-in.
If you decide to write your own add-in, you should make sure you avoid infinite loops and stack overflows as they would freeze the spreadsheet.
fdbf5cc7-5590-40a9-85e5-a51817e1c575|1|5.0
Tags: