跳到主要内容

IF

Checks whether a condition is met, and returns one value if -true, and another value if -false.

Syntax

expression.IF(arg1, arg2, arg3);

expression - A variable that represents a ApiWorksheetFunction class.

Parameters

NameRequired/OptionalData typeDefaultDescription
arg1Requirednumber | string | ApiRange | ApiName | booleanAny value or expression that can be evaluated to -true or -false.
arg2Requirednumber | string | ApiRange | ApiName | booleanThe value that is returned if the condition is -true. If omitted, -true is returned. You can nest up to seven IF functions.
arg3OptionalApiRange | ApiName | number | string | booleanThe value that is returned if the condition is -false. If omitted, -false is returned.

Returns

number | string | boolean

Example

let worksheet = Api.GetActiveSheet();
let func = Api.GetWorksheetFunction();
worksheet.GetRange("A1").SetValue(func.IF("12<100", 0, 1));