2019独角兽企业重金招聘Python工程师标准>>>
How to write function in JDataGrid Spreadsheet Edition?
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.addFunction(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.
查看原文
--------------------------
新闻: 国际知识产权联盟公布盗版重点观察国名单
导航: 博客园首页 知识库 新闻 招聘 社区 小组 博问 网摘 找找看