ExcelScript.PresetCriteriaConditionalFormat interface
表示预设条件条件格式,例如高于平均值、低于平均值、唯一值、包含空白、非空白、错误和无错误。
注解
示例
/**
* This script applies a conditional format that uses a preset criterion.
* Any cell in row 1 will have the color fill set to green if it is a duplicate value
* (of anything else in row 1).
*/
function main(workbook: ExcelScript.Workbook) {
// Get the range for row 1.
const sheet = workbook.getActiveWorksheet();
const formattedRange = sheet.getRange("1:1");
// Add new conditional formatting to that range.
const conditionalFormat = formattedRange.addConditionalFormat(
ExcelScript.ConditionalFormatType.presetCriteria);
// Set the conditional formatting to apply a green fill.
const presetFormat: ExcelScript.PresetCriteriaConditionalFormat = conditionalFormat.getPreset();
presetFormat.getFormat().getFill().setColor("green");
// Set a rule to apply the conditional format when values are duplicated in the range.
const duplicateRule: ExcelScript.ConditionalPresetCriteriaRule = {
criterion: ExcelScript.ConditionalFormatPresetCriterion.duplicateValues
};
presetFormat.setRule(duplicateRule);
}
方法
get |
返回格式对象,该对象封装条件格式字体、填充、边框和其他属性。 |
get |
条件格式的规则。 |
set |
条件格式的规则。 |
方法详细信息
getFormat()
返回格式对象,该对象封装条件格式字体、填充、边框和其他属性。
getFormat(): ConditionalRangeFormat;
返回
getRule()
setRule(rule)
条件格式的规则。
setRule(rule: ConditionalPresetCriteriaRule): void;
参数
返回
void