Quantcast
Channel: ClosedXML - The easy way to OpenXML
Viewing all articles
Browse latest Browse all 1877

Created Unassigned: IF-function doesn't handle 2 arguments [9366]

$
0
0
Hi!

Currently ClosedXML is only able to handle the "IF"-function if supplied with 3 arguments, but this function can also be called with only 2 arguments. ie. something like "IF(M49="111";94)" will return 0 if the predicate is false.

Modifications are necessary in the file "Logical.cs", two methods need to be updated:
```
public static void Register(CalcEngine ce)
{
ce.RegisterFunction("AND", 1, int.MaxValue, And);
ce.RegisterFunction("OR", 1, int.MaxValue, Or);
ce.RegisterFunction("NOT", 1, Not);
ce.RegisterFunction("IF", 2, 3, If);
ce.RegisterFunction("TRUE", 0, True);
ce.RegisterFunction("FALSE", 0, False);
}
```
and
```
static object If(List<Expression> p)
{
if (p.Count == 2) {
var val = p[1].Evaluate();
return (bool) p[0]
? val
: val.GetType().IsValueType
? Activator.CreateInstance(val.GetType())
: null;
} else {
return (bool)p[0]
? p[1].Evaluate()
: p[2].Evaluate();
}
}
```

Cheers,
Ted

Viewing all articles
Browse latest Browse all 1877

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>