存取條件式格式設定規則。如要建立新規則,請使用 SpreadsheetApp.newConditionalFormatRule()
和 ConditionalFormatRuleBuilder
。您可以使用 Sheet.setConditionalFormatRules(rules)
為特定工作表設定規則。
方法
方法 | 傳回類型 | 簡短說明 |
---|---|---|
copy() | ConditionalFormatRuleBuilder | 使用這項規則的設定傳回規則建構工具預設設定。 |
getBooleanCondition() | BooleanCondition | 如果這項規則使用布林條件條件,就會擷取規則的 BooleanCondition 資訊。 |
getGradientCondition() | GradientCondition | 如果這項規則使用漸層條件條件,就會擷取規則的 GradientCondition 資訊。 |
getRanges() | Range[] | 擷取套用這項條件格式規則的範圍。 |
內容詳盡的說明文件
copy()
getBooleanCondition()
如果這項規則使用布林條件條件,就會擷取規則的 BooleanCondition
資訊。否則會傳回 null
。
// Log the boolean criteria type of the first conditional format rules of a sheet. var rule = SpreadsheetApp.getActiveSheet().getConditionalFormatRules()[0]; var booleanCondition = rule.getBooleanCondition(); if (booleanCondition != null) { Logger.log(booleanCondition.getCriteriaType()); }
回攻員
BooleanCondition
:布林值條件物件,如果規則未使用布林條件,則為 null
。
getGradientCondition()
如果這項規則使用漸層條件條件,就會擷取規則的 GradientCondition
資訊。否則會傳回 null
。
// Log the gradient minimum color of the first conditional format rule of a sheet. var rule = SpreadsheetApp.getActiveSheet().getConditionalFormatRules()[0]; var gradientCondition = rule.getGradientCondition(); if (gradientCondition != null) { // Assume the color has ColorType.RGB. Logger.log(gradientCondition.getMinColorObject().asRgbColor().asHexString()); }
回攻員
GradientCondition
:漸層條件物件,如果規則未使用漸層條件,則會傳回 null
。
getRanges()
擷取套用這項條件格式規則的範圍。
// Log each range of the first conditional format rule of a sheet. var rule = SpreadsheetApp.getActiveSheet().getConditionalFormatRules()[0]; var ranges = rule.getRanges(); for (var i = 0; i < ranges.length; i++) { Logger.log(ranges[i].getA1Notation()); }
回攻員
Range[]
:要套用這項條件格式規則的範圍。