Extreme Component Documentation

How to write function in JDataGrid Spreadsheet Edition?

May 6,2008

1. Understand the formula and function API used in JDataGrid Spreadsheet Edition?

Obviously you should understand the “Function” and it’s sub class.
  The central method of Function interface is “Object evaluate(FormulaContext ctx, List args)”, the method have the “FormulaContext” and List based arguments.

  Override the method “evaluate(FormulaContext ctx, List args)” and write your logic in the method body, finally return the result, you can override the AbstractFunction directly or implements the Function interface, don’t forget invoke super(name) when use AbstractFuction.

  Note: The important point need to mention is you should invoke the method “CellUtils.getObject”, “CellUtils.stringValue” to get every argument’s value, this is impossible before the JDataGrid Spreedsheet Edition 2.5.0, since the CellUtils is package private, the developer need copy the “CellUtils” class before the version 2.5.0, the good news is the API now open to public after version 2.5.0.

2. Add the function to the FormulaFactory.

 The FormulaFactory provides the several methods to add or remove the function.

FormulaFactory. removeFunction(String);
FormulaFactory. getAllFunctionNames();
FormulaFactory. getFunction(String);

The function you added will be the CellFunctionType.CUSTOM by default, these functions will be lists in “Custom” category in the choose function dialog, this is a new feature in JDataGrid 2.5.0.


Subscribe RSS >>download

Send Us Feedback