跳到主要内容

Add

向集合添加新的格式条件。

语法

expression.Add(Type, Operator, Formula1, Formula2);

expression - 表示 ApiFormatConditions 类的变量。

参数

名称必需/可选数据类型默认值描述
Type必需XlFormatConditionType格式条件类型。
Operator可选XlFormatConditionOperator格式条件运算符。
Formula1可选string | number | ApiRange第一个公式。
Formula2可选string | number | ApiRange第二个公式。

返回值

ApiFormatCondition | null

示例

当电子表格中的单元格值满足条件时自动高亮显示。

// How do I create a rule that colors cells based on whether they are above or below a threshold in a spreadsheet?

// Set up automatic cell formatting that reacts to the data entered in a spreadsheet.

let worksheet = Api.GetActiveSheet();

worksheet.GetRange("A1").SetValue("Sales Data");
worksheet.GetRange("A2").SetValue(100);
worksheet.GetRange("A3").SetValue(250);
worksheet.GetRange("A4").SetValue(150);
worksheet.GetRange("A5").SetValue(300);
worksheet.GetRange("A6").SetValue(75);

let dataRange = worksheet.GetRange("A2:A6");

let formatConditions = dataRange.GetFormatConditions();

let condition1 = formatConditions.Add("xlCellValue", "xlGreater", "200");
if (condition1) {
condition1.SetFillColor(Api.CreateColorFromRGB(255, 0, 0));
}