跳到主要内容

IF

检查是否满足条件,如果为 true 返回一个值,如果为 false 返回另一个值。

语法

expression.IF(arg1, arg2, arg3);

expression - 表示 ApiWorksheetFunction 类的变量。

参数

名称必需/可选数据类型默认值描述
arg1必需number | string | ApiRange | ApiName | boolean可以计算为 truefalse 的任何值或表达式。
arg2必需number | string | ApiRange | ApiName | boolean条件为 true 时返回的值。如果省略,则返回 true。最多可以嵌套七个 IF 函数。
arg3可选ApiRange | ApiName | number | string | boolean条件为 false 时返回的值。如果省略,则返回 false

返回值

number | string | boolean

示例

根据条件在电子表格中为真或假返回不同的值。

// How do I test a condition and display different results in a spreadsheet?

// Execute conditional logic to display specific values when criteria are met in a spreadsheet.

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