在 Conditional 中存取布林條件。每條條件式格式規則只能包含一個布林條件。布林條件本身包含布林準則 (含值) 和格式設定。系統會根據儲存格內容評估條件,並傳回 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。 |
內容詳盡的說明文件
get Background Object()
取得這個布林條件的背景顏色。如果未設定,則傳回 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 (如果未針對此條件設定)。
get Bold()
如果這個布林條件會將文字設為粗體,則傳回 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:粗體設定是否不受影響
get Criteria Type()
取得 Boolean 列舉中定義的規則條件類型。如要取得條件的引數,請使用 get。如要使用這些值建立或修改條件式格式設定規則,請參閱Conditional。
// 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}`); } });
回攻員
Boolean:條件式格式設定條件的類型。
get Criteria Values()
取得規則條件的引數陣列。如要取得條件類型,請使用 get。如要使用這些值建立或修改條件式格式設定規則,請參閱Conditional。
// 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[]:適合規則條件類型的引數陣列;引數數量和類型與 Conditional 類別的對應 when...() 方法相符。
get Font Color Object()
取得這個布林條件的字型顏色。如果未設定,則傳回 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 (如果未針對此條件設定)。
get Italic()
如果這個布林條件會將文字設為斜體,則傳回 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:斜體不受影響
get Strikethrough()
如果這個布林值條件會為文字加上刪除線,則傳回 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:刪除線是否不受影響
get Underline()
如果這個布林條件會為文字加上底線,則傳回 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:底線是否不受影響