Class BooleanCondition

布林值條件

ConditionalFormatRules 中存取布林條件。每條條件式格式規則只能包含一個布林條件。布林條件本身包含布林準則 (含值) 和格式設定。系統會根據儲存格內容評估條件,並傳回 truefalse 值。如果條件評估結果為 true,系統就會將條件的格式設定套用至儲存格。

方法

方法傳回類型簡短說明
getBackgroundObject()Color|null取得這個布林條件的背景顏色。
getBold()Boolean|null如果這個布林條件會將文字設為粗體,則傳回 true;如果這個布林條件會移除文字的粗體格式,則傳回 false
getCriteriaType()BooleanCriteria取得 BooleanCriteria 列舉中定義的規則條件類型。
getCriteriaValues()Object[]取得規則條件的引數陣列。
getFontColorObject()Color|null取得這個布林條件的字型顏色。
getItalic()Boolean|null如果這個布林條件會將文字設為斜體,則傳回 true;如果這個布林條件會移除文字的斜體格式,則傳回 false
getStrikethrough()Boolean|null如果這個布林值條件會為文字加上刪除線,則傳回 true;如果這個布林值條件會移除文字的刪除線,則傳回 false
getUnderline()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:底線是否不受影響

已淘汰的方法