介绍自定义JDataGrid电子表格版本公式中的函数?

本文介绍如何在JDataGridSpreadsheet版中编写自定义函数,包括理解Function接口及其实现方法evaluate,以及如何通过FormulaFactory注册这些函数。自定义函数默认会被归类为CUSTOM类型,并在选择函数对话框中的‘Custom’类别下列出。

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.

insert-function-dialog


查看原文


1386853.html?type=1

--------------------------
新闻: 国际知识产权联盟公布盗版重点观察国名单
导航: 博客园首页   知识库   新闻   招聘   社区   小组   博问   网摘   找找看

转载于:https://my.oschina.net/javastudy/blog/27

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值