Class BooleanCondition

BooleanCondition

Access boolean conditions in ConditionalFormatRules. Each conditional format rule may contain a single boolean condition. The boolean condition itself contains a boolean criteria (with values) and formatting settings. The criteria is evaluated against the content of a cell resulting in either a true or false value. If the criteria evaluates to true, the condition's formatting settings are applied to the cell.

Methods

MethodReturn typeBrief description
getBackground()StringGets the background color string for this boolean condition.
getBold()BooleanReturns true if this boolean condition bolds the text and returns false if this boolean condition removes bolding from the text.
getCriteriaType()BooleanCriteriaGets the rule's criteria type as defined in the BooleanCriteria enum.
getCriteriaValues()Object[]Gets an array of arguments for the rule's criteria.
getFontColor()StringGets the font color string for this boolean condition.
getItalic()BooleanReturns true if this boolean condition italicises the text and returns false if this boolean condition removes italics from the text.
getStrikethrough()BooleanReturns true if this boolean condition strikes through the text and returns false if this boolean condition removes strikethrough from the text.
getUnderline()BooleanReturns true if this boolean condition underlines the text and returns false if this boolean condition removes underlining from the text.

Detailed documentation

getBackground()

Gets the background color string for this boolean condition. Returns null if not set.

// Logs the boolean condition background color for each conditional format rule on a sheet.
var sheet = SpreadsheetApp.getActiveSheet();
var rules = sheet.getConditionalFormatRules();
for (int i = 0; i < rules.length; i++) {
  var color = rules[i].getBooleanCondition().getBackground();
  Logger.log("The background color for rule %d is %s", i, color);
}

Return

String — the background color string, or null if not set for this condition


getBold()

Returns true if this boolean condition bolds the text and returns false if this boolean condition removes bolding from the text. Returns null if bolding is unaffected.

// Logs the boolean condition font weight for each conditional format rule on a sheet.
var sheet = SpreadsheetApp.getActiveSheet();
var rules = sheet.getConditionalFormatRules();
for (int i = 0; i < rules.length; i++) {
  var bold = rules[i].getBooleanCondition().getBold();
  Logger.log("The font bold setting for rule %d is %b", i, weight);
}

Return

Boolean — whether or not the boolean condition bolds the text, or null if bolding is unaffected


getCriteriaType()

Gets the rule's criteria type as defined in the BooleanCriteria enum. To get the arguments for the criteria, use getCriteriaValues(). To use these values to create or modify a conditional formatting rule, see ConditionalFormatRuleBuilder.withCriteria(criteria, args).

// Log information about the conditional formats on the active sheet that use
// boolean conditions.
var sheet = SpreadsheetApp.getActiveSheet;
var formats = sheet.getConditionalFormats();
sheet.getConditionalFormats().forEach(function(format) {
  var booleanCondition = format.getBooleanCondition();
  if (booleanCondition) {
    var criteria = booleanCondition.getCriteriaType();
    var args = booleanCondition.getCriteriaValues();
    Logger.log('The conditional format rule is %s %s', criteria, args);
  }
});

Return

BooleanCriteria — the type of conditional formatting criteria


getCriteriaValues()

Gets an array of arguments for the rule's criteria. To get the criteria type, use getCriteriaType(). To use these values to create or modify a conditional formatting rule, see ConditionalFormatRuleBuilder.withCriteria(criteria, args).

// Log information about the conditional formats on the active sheet that use
// boolean conditions.
var sheet = SpreadsheetApp.getActiveSheet;
var formats = sheet.getConditionalFormats();
sheet.getConditionalFormats().forEach(function(format) {
  var booleanCondition = format.getBooleanCondition();
  if (booleanCondition) {
    var criteria = booleanCondition.getCriteriaType();
    var args = booleanCondition.getCriteriaValues();
    Logger.log('The conditional format rule is %s %s', criteria, args);
  }
});

Return

Object[] — an array of arguments appropriate to the rule's criteria type; the number of arguments and their type match the corresponding when...() method of the ConditionalFormatRuleBuilder class


getFontColor()

Gets the font color string for this boolean condition. Returns null if not set.

// Logs the boolean condition font color for each conditional format rule on a sheet.
var sheet = SpreadsheetApp.getActiveSheet();
var rules = sheet.getConditionalFormatRules();
for (int i = 0; i < rules.length; i++) {
  var color = rules[i].getBooleanCondition().getFontColor();
  Logger.log("The font color for rule %d is %s", i, color);
}

Return

String — the font color string, or null if not set for this condition


getItalic()

Returns true if this boolean condition italicises the text and returns false if this boolean condition removes italics from the text. Returns null if italics are unaffected.

// Logs the boolean condition font style for each conditional format rule on a sheet.
var sheet = SpreadsheetApp.getActiveSheet();
var rules = sheet.getConditionalFormatRules();
for (int i = 0; i < rules.length; i++) {
  var italic = rules[i].getBooleanCondition().getItalic();
  Logger.log("The font italic setting for rule %d is %b", i, italic);
}

Return

Boolean — whether or not the boolean condition italicises the text, or null if italicising is unaffected


getStrikethrough()

Returns true if this boolean condition strikes through the text and returns false if this boolean condition removes strikethrough from the text. Returns null if strikethrough is unaffected.

// Logs the boolean condition strikethrough setting for each conditional format rule on a
// sheet.
var sheet = SpreadsheetApp.getActiveSheet();
var rules = sheet.getConditionalFormatRules();
for (int i = 0; i < rules.length; i++) {
  var strikethrough = rules[i].getBooleanCondition().getStrikethrough();
  Logger.log("The font strikethrough setting for rule %d is %b", i, strikethrough);
}

Return

Boolean — whether or not the boolean condition strikes through the text, or null if strikethrough is unaffected


getUnderline()

Returns true if this boolean condition underlines the text and returns false if this boolean condition removes underlining from the text. Returns null if underlining is unaffected.

// Logs the boolean condition underline setting for each conditional format rule on a sheet.
var sheet = SpreadsheetApp.getActiveSheet();
var rules = sheet.getConditionalFormatRules();
for (int i = 0; i < rules.length; i++) {
  var underline = rules[i].getBooleanCondition().getUnderline();
  Logger.log("The font underline setting for rule %d is %b", i, underline);
}

Return

Boolean — whether or not the boolean condition underlines the text, or null if underlining is unaffected

发送以下问题的反馈:

此网页
Apps Script
Apps Script
需要帮助?请访问我们的支持页面