function sum01(col, row){
var cell1 = this.getCellValue(0, row);
var cell2 = this.getCellValue(1, row);
return cell1 + cell2;
}
obj.setCellData(sum01, 2); // sum of col0 and col1 in col2
function sum(col1, col2){
return function(col, row){
var cell1 = this.getCellValue(col1, row);
var cell2 = this.getCellValue(col2, row);
return cell1 + cell2;
}
}
obj.setCellData(sum(0, 1), 2); // sum of col0 and col1 in col2
function formula(operation){
return function(col1, col2){
return function(col, row){
var cell1 = this.getCellValue(col1, row);
var cell2 = this.getCellValue(col2, row);
return operation(cell1, cell2);
}
}
}
var sum = formula(function(a,b){return a+b});
var diff = formula(function(a,b){return a-b});
var product = formula(function(a,b){return a*b});
obj.setCellData(sum(0, 1), 2); // sum of col0 and col1 in col2
function col(i){
return function(c, r){
return this.getCellValue(i, r);
}
}
function formula(operation){
return function(arg1, arg2){
return function(c, r){
var value1 = (typeof(arg1)=='function' ? arg1.call(this, c, r) : arg1);
var value2 = (typeof(arg2)=='function' ? arg2.call(this, c, r) : arg2);
return operation(value1, value2);
}
}
}
var sum = formula(function(a,b){return a+b});
var diff = formula(function(a,b){return a-b});
var product = formula(function(a,b){return a*b});
obj.setCellData(sum(col(0), col(1)), 2); // col2 = col0 + col1
obj.setCellData(diff(product(col(3), 1000), col(4)), 5); // col5 = col3 * 1000 - col4
This topic is archived.