- /** 自定义函数开始 */
- function getFormulaFunction() {
- this.name = "GETFORMULA";
- this.maxArgs = 3;
- this.minArgs = 1;
- }
- getFormulaFunction.prototype = new GC.Spread.CalcEngine.Functions.Function();
- getFormulaFunction.prototype.acceptsReference = function (argIndex) {
- if(argIndex === 0 || argIndex === 1 || argIndex === 2){
- return true;
- }
- return false;
- }
- getFormulaFunction.prototype.isContextSensitive = function(){
- return true;
- }
- getFormulaFunction.prototype.evaluate = function (context,arg1,arg2,arg3) {
- debugger
- console.log(arg1.getRowCount()+",列:"+arg1.getColumnCount());
- var result = 1;
- if(arg1.getRowCount() > 1 || arg1.getColumnCount() > 1){
- debugger
- var sheet = spread.getActiveSheet();
- var selectedValue = [];
- for(var i=0;i<arg1.getRowCount();i++){
- for(var j=0;j<arg1.getColumnCount();j++){
- var value = sheet.getValue(arg1.getRow()+i,arg1.getColumn()+j);
- if(value){
- selectedValue.push(value);
- }
- }
- }
- var result = sum(selectedValue);
- sheet.setValue(10, arg2.getColumn(), result + "_b")
- sheet.setValue(arg3.getRow(), arg3.getColumn(), result + "_c")
- return result + "_a";
- }
- return "#VALUE!";
- };
- designer.wrapper.spread.getActiveSheet().addCustomFunction(new getFormulaFunction());
- GC.Spread.CalcEngine.Functions.defineGlobalCustomFunction("GETFORMULA", new getFormulaFunction());
- /** 自定义函数结束 */
复制代码 |