TrimPath Forum


About TrimPath stuff, like Junction, Next Action, JavaScript Templates, TrimQuery, TrimSpreadsheet, etc...

You are not logged in.

#1 2007-05-03 00:03:46

Matt Wlazlo
New member
Registered: 2007-05-03
Posts: 3

IF(cond;then;else)

Hi,

I came up with this little patch to allow IF statements in the spreadsheet engine. Hope someone finds it useful.

Code:

--- /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 = [];^M

Offline

 

#2 2008-01-19 19:34:33

shawn
New member
Registered: 2008-01-18
Posts: 5

Re: IF(cond;then;else)

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

 

#3 2008-05-21 05:24:56

Matt Wlazlo
New member
Registered: 2007-05-03
Posts: 3

Re: IF(cond;then;else)

The patch changes 2 lines. If you change the other one, as prescribed in the PATCH, it should work.

Offline

 

Board footer

Powered by PunBB
© Copyright 2002–2005 Rickard Andersson