method.
FlexSheet will parse the cell reference parameter such as 'A1' or 'A1:B2' to a
flexSheet.addCustomFunction('customSumProduct', function (range1, range2) {
var flexSheet = $scope.ctx.flexSheet,
result = 0,
val1, val2;
if (range1.rowSpan === range2.rowSpan && range1.columnSpan === range2.columnSpan) {
for (var rowIndex = 0; rowIndex < range1.rowSpan; rowIndex++) {
for (var columnIndex = 0; columnIndex < range1.columnSpan; columnIndex++) {
val1 = +flexSheet.getCellValue(range1.topRow + rowIndex, range1.leftCol + columnIndex, false);
val2 = +flexSheet.getCellValue(range2.topRow + rowIndex, range2.leftCol + columnIndex, false);
result += val1 * val2;
}
}
}
return result;
}, 'Custom SumProduct Function', 2, 2);
FlexSheet also allows user to process non-supported functions met in cell expressions by the
event.
This event will pass the 'UnKnownFunctionEventArgs' to customer. This 'UnKnownFunctionEventArgs' provides the function name and the evaluated values list of the parameters.
Customer can set the 'value' field of 'UnKnownFunctionEventArgs' to customize the miss formula result.
Otherwise the missed function will return the default error message:
.
flexSheet.unknownFunction.addHandler(function (sender, e) {
var result = '';
if (e.params) {
for (var i = 0; i < e.params.length; i++) {
result += e.params[i];
}
}
e.value = result;
});