访问 ConditionalFormatRules 中的布尔条件。每条条件格式规则可能包含一个布尔条件。布尔条件本身包含一个布尔条件(带值)和格式设置。系统会根据单元格的内容评估条件,结果为 true 或 false 值。如果条件的评估结果为 true,则会将条件的格式设置应用于单元格。
方法
| 方法 | 返回值类型 | 简介 |
|---|---|---|
get | Color|null | 获取此布尔条件的背景颜色。 |
get | Boolean|null | 如果此布尔条件将文本加粗,则返回 true;如果此布尔条件从文本中移除加粗,则返回 false。 |
get | Boolean | 获取规则的条件类型,如 Boolean 枚举中所定义。 |
get | Object[] | 获取规则条件的实参数组。 |
get | Color|null | 获取此布尔条件的字体颜色。 |
get | Boolean|null | 如果此布尔条件将文本设为斜体,则返回 true;如果此布尔条件从文本中移除斜体,则返回 false。 |
get | Boolean|null | 如果此布尔条件为文本添加删除线,则返回 true;如果此布尔条件从文本中移除删除线,则返回 false。 |
get | Boolean|null | 如果此布尔条件为文本添加下划线,则返回 true;如果此布尔条件从文本中移除下划线,则返回 false。 |
详细文档
getBackgroundObject()
获取此布尔条件的背景颜色。如果未设置,则返回 null。
// Logs the boolean condition background color for each conditional format rule // on a sheet. const sheet = SpreadsheetApp.getActiveSheet(); const rules = sheet.getConditionalFormatRules(); for (const rule of rules) { const color = rule.getBooleanCondition().getBackgroundObject(); Logger.log(`Background color: ${color.asRgbColor().asHexString()}`); }
返回
Color|null - 背景颜色;如果未为此条件设置,则返回 null。
getBold()
如果此布尔条件将文本加粗,则返回 true;如果此布尔条件从文本中移除加粗,则返回 false。如果加粗不受影响,则返回 null。
// Logs the boolean condition font weight for each conditional format rule on a // sheet. const sheet = SpreadsheetApp.getActiveSheet(); const rules = sheet.getConditionalFormatRules(); for (const rule of rules) { const bold = rule.getBooleanCondition().getBold(); Logger.log(`Bold: ${bold}`); }
返回
Boolean|null - 布尔条件是否将文本加粗;如果加粗不受影响,则返回 null
getCriteriaType()
获取规则的条件类型,如 BooleanCriteria 枚举中所定义。如需获取条件的实参,请使用 getCriteriaValues()。如需使用这些值创建或修改条件格式规则,请参阅 ConditionalFormatRuleBuilder.withCriteria(criteria, args)。
// Log information about the conditional formats on the active sheet that use // boolean conditions. const formats = SpreadsheetApp.getActiveSheet.getConditionalFormats(); SpreadsheetApp.getActiveSheet.getConditionalFormats().forEach((format) => { const booleanCondition = format.getBooleanCondition(); if (booleanCondition) { const criteria = booleanCondition.getCriteriaType(); const args = booleanCondition.getCriteriaValues(); Logger.log(`The conditional format rule is ${criteria} ${args}`); } });
返回
BooleanCriteria - 条件格式条件的类型。
getCriteriaValues()
获取规则条件的实参数组。如需获取条件类型,请使用 getCriteriaType()。如需使用这些值创建或修改条件格式规则,请参阅 ConditionalFormatRuleBuilder.withCriteria(criteria, args)。
// Log information about the conditional formats on the active sheet that use // boolean conditions. const formats = SpreadsheetApp.getActiveSheet.getConditionalFormats(); SpreadsheetApp.getActiveSheet.getConditionalFormats().forEach((format) => { const booleanCondition = format.getBooleanCondition(); if (booleanCondition) { const criteria = booleanCondition.getCriteriaType(); const args = booleanCondition.getCriteriaValues(); Logger.log(`The conditional format rule is ${criteria} ${args}`); } });
返回
Object[] - 适合规则条件类型的实参数组;实参的数量及其类型与 ConditionalFormatRuleBuilder 类的相应 when...() 方法匹配。
getFontColorObject()
获取此布尔条件的字体颜色。如果未设置,则返回 null。
// Logs the boolean condition font color for each conditional format rule on a // sheet. const sheet = SpreadsheetApp.getActiveSheet(); const rules = sheet.getConditionalFormatRules(); for (const rule of rules) { const color = rule.getBooleanCondition().getFontColorObject(); Logger.log(`Font color: ${color.asRgbColor().asHexString()}`); }
返回
Color|null - 字体颜色;如果未为此条件设置,则返回 null。
getItalic()
如果此布尔条件将文本设为斜体,则返回 true;如果此布尔条件从文本中移除斜体,则返回 false。如果斜体不受影响,则返回 null。
// Logs the boolean condition font style for each conditional format rule on a // sheet. const sheet = SpreadsheetApp.getActiveSheet(); const rules = sheet.getConditionalFormatRules(); for (const rule of rules) { const italic = rule.getBooleanCondition().getItalic(); Logger.log(`Italic: ${italic}`); }
返回
Boolean|null - 布尔条件是否将文本设为斜体;如果斜体不受影响,则返回 null
getStrikethrough()
如果此布尔条件为文本添加删除线,则返回 true;如果此布尔条件从文本中移除删除线,则返回 false。如果删除线不受影响,则返回 null。
// Logs the boolean condition strikethrough setting for each conditional format // rule on a sheet. const sheet = SpreadsheetApp.getActiveSheet(); const rules = sheet.getConditionalFormatRules(); for (const rule of rules) { const strikethrough = rule.getBooleanCondition().getStrikethrough(); Logger.log(`Strikethrough: ${strikethrough}`); }
返回
Boolean|null - 布尔条件是否为文本添加删除线;如果删除线不受影响,则返回 null
getUnderline()
如果此布尔条件为文本添加下划线,则返回 true;如果此布尔条件从文本中移除下划线,则返回 false。如果下划线不受影响,则返回 null。
// Logs the boolean condition underline setting for each conditional format rule // on a sheet. const sheet = SpreadsheetApp.getActiveSheet(); const rules = sheet.getConditionalFormatRules(); for (const rule of rules) { const underline = rule.getBooleanCondition().getUnderline(); Logger.log(`Underline: ${underline}`); }
返回
Boolean|null - 布尔条件是否为文本添加下划线;如果
下划线不受影响,则返回 null