About TrimPath stuff, like Junction, Next Action, JavaScript Templates, TrimQuery, TrimSpreadsheet, etc...
You are not logged in.
Hi,
I came up with this little patch to allow IF statements in the spreadsheet engine. Hope someone finds it useful.
--- /tmp/trimpath/spreadsheet_engine.js 2005-02-13 05:17:35.000000000 +1100
+++ spreadsheet_engine.js 2007-05-03 09:59:46.000000000 +1000
@@ -39,7 +39,8 @@
COUNT : function(values) { return fold(values, COUNT2, 0); },^M
SUM : function(values) { return fold(values, SUM2, 0); },^M
MAX : function(values) { return fold(values, MAX2, theNumber.MIN_VALUE); },^M
- MIN : function(values) { return fold(values, MIN2, theNumber.MAX_VALUE); }^M
+ MIN : function(values) { return fold(values, MIN2, theNumber.MAX_VALUE); },^M
+ IF : function(cond, then, or) { return (cond ? then : or); }^M
},^M
calc : function(cellProvider, context, startFuel) {^M
// Returns null if all done with a complete calc() run.^M
@@ -177,6 +178,7 @@
^M
// Parse formula (without "=" prefix) like "123+SUM(A1:A6)/D5" into JavaScript expression string.^M
var parseFormula = TrimPath.TEST.parseFormula = function(formula, dependencies) { ^M
+ formula = formula.replace(/;/g, ","); // turn function separators into something callable^M
var arrayReferencesFixed = formula.replace(/\$?([A-Z]+)\$?([0-9]+):\$?([A-Z]+)\$?([0-9]+)/g,^M
function(ignored, startColStr, startRowStr, endColStr, endRowStr) {^M
var res = [];^MOffline
So, I just added this line:
IF : function(cond, then, or) { return (cond ? then : or); }
is that the only thing?
Can you give an example of what the if statement would look like?
I tried: =IF(A1=8,1,0)
but I just got #VALUE in the cell.
Offline
The patch changes 2 lines. If you change the other one, as prescribed in the PATCH, it should work.
Offline