Class ConditionalFormatRule
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
详细文档
getBooleanCondition()
如果相应规则使用布尔值条件标准,则检索该规则的 BooleanCondition
信息。否则返回 null
。
// Log the boolean criteria type of the first conditional format rules of a
// sheet.
const rule = SpreadsheetApp.getActiveSheet().getConditionalFormatRules()[0];
const 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.
const rule = SpreadsheetApp.getActiveSheet().getConditionalFormatRules()[0];
const 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.
const rule = SpreadsheetApp.getActiveSheet().getConditionalFormatRules()[0];
const ranges = rule.getRanges();
for (let i = 0; i < ranges.length; i++) {
Logger.log(ranges[i].getA1Notation());
}
返回
Range[]
- 应用相应条件格式规则的范围。
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-08-05。
[null,null,["最后更新时间 (UTC):2025-08-05。"],[[["\u003cp\u003e\u003ccode\u003eXFrameOptionsMode\u003c/code\u003e is used to control how a client-side Apps Script HTML Service output can be embedded in iframes on other websites.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003eALLOWALL\u003c/code\u003e permits any site to embed the page, demanding developer-implemented clickjacking protection, while \u003ccode\u003eDEFAULT\u003c/code\u003e maintains standard security with no \u003ccode\u003eX-Frame-Options\u003c/code\u003e header.\u003c/p\u003e\n"],["\u003cp\u003eIf a script doesn't explicitly set a mode, Apps Script defaults to \u003ccode\u003eDEFAULT\u003c/code\u003e, ensuring standard security behaviors are in effect.\u003c/p\u003e\n"]]],["Conditional format rules can be accessed and managed using the provided methods. New rules are created via `SpreadsheetApp.newConditionalFormatRule()`. Existing rules can be copied with `copy()`, retrieving a builder with the same settings. The `getBooleanCondition()` and `getGradientCondition()` methods fetch information based on the rule's criteria, while `getRanges()` retrieves the ranges the rule applies to. `Sheet.setConditionalFormatRules(rules)` applies rule settings to a given sheet.\n"],null,["# Class ConditionalFormatRule\n\nConditionalFormatRule\n\nAccess conditional formatting rules. To create a new rule, use [SpreadsheetApp.newConditionalFormatRule()](/apps-script/reference/spreadsheet/spreadsheet-app#newConditionalFormatRule()) and [ConditionalFormatRuleBuilder](/apps-script/reference/spreadsheet/conditional-format-rule-builder).\nYou can use [Sheet.setConditionalFormatRules(rules)](/apps-script/reference/spreadsheet/sheet#setConditionalFormatRules(ConditionalFormatRule)) to set the\nrules for a given sheet. \n\n### Methods\n\n| Method | Return type | Brief description |\n|---------------------------------------------------|----------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| [copy()](#copy()) | [ConditionalFormatRuleBuilder](/apps-script/reference/spreadsheet/conditional-format-rule-builder) | Returns a rule builder preset with this rule's settings. |\n| [getBooleanCondition()](#getBooleanCondition()) | [BooleanCondition](/apps-script/reference/spreadsheet/boolean-condition) | Retrieves the rule's [BooleanCondition](/apps-script/reference/spreadsheet/boolean-condition) information if this rule uses boolean condition criteria. |\n| [getGradientCondition()](#getGradientCondition()) | [GradientCondition](/apps-script/reference/spreadsheet/gradient-condition) | Retrieves the rule's [GradientCondition](/apps-script/reference/spreadsheet/gradient-condition) information, if this rule uses gradient condition criteria. |\n| [getRanges()](#getRanges()) | [Range[]](/apps-script/reference/spreadsheet/range) | Retrieves the ranges to which this conditional format rule is applied. |\n\nDetailed documentation\n----------------------\n\n### `copy()`\n\nReturns a rule builder preset with this rule's settings.\n\n#### Return\n\n\n[ConditionalFormatRuleBuilder](/apps-script/reference/spreadsheet/conditional-format-rule-builder) --- A builder based on this rule's settings.\n\n*** ** * ** ***\n\n### `get``Boolean``Condition()`\n\nRetrieves the rule's [BooleanCondition](/apps-script/reference/spreadsheet/boolean-condition) information if this rule uses\nboolean condition criteria. Otherwise returns `null`.\n\n```javascript\n// Log the boolean criteria type of the first conditional format rules of a\n// sheet.\nconst rule = SpreadsheetApp.getActiveSheet().getConditionalFormatRules()[0];\nconst booleanCondition = rule.getBooleanCondition();\nif (booleanCondition != null) {\n Logger.log(booleanCondition.getCriteriaType());\n}\n```\n\n#### Return\n\n\n[BooleanCondition](/apps-script/reference/spreadsheet/boolean-condition) --- The boolean condition object, or `null` if the rule does not use a boolean\ncondition.\n\n*** ** * ** ***\n\n### `get``Gradient``Condition()`\n\nRetrieves the rule's [GradientCondition](/apps-script/reference/spreadsheet/gradient-condition) information, if this rule\nuses gradient condition criteria. Otherwise returns `null`.\n\n```javascript\n// Log the gradient minimum color of the first conditional format rule of a\n// sheet.\nconst rule = SpreadsheetApp.getActiveSheet().getConditionalFormatRules()[0];\nconst gradientCondition = rule.getGradientCondition();\nif (gradientCondition != null) {\n // Assume the color has ColorType.RGB.\n Logger.log(gradientCondition.getMinColorObject().asRgbColor().asHexString());\n}\n```\n\n#### Return\n\n\n[GradientCondition](/apps-script/reference/spreadsheet/gradient-condition) --- The gradient condition object, or `null` if the rule does not use a gradient\ncondition.\n\n*** ** * ** ***\n\n### `get``Ranges()`\n\nRetrieves the ranges to which this conditional format rule is applied.\n\n```javascript\n// Log each range of the first conditional format rule of a sheet.\nconst rule = SpreadsheetApp.getActiveSheet().getConditionalFormatRules()[0];\nconst ranges = rule.getRanges();\nfor (let i = 0; i \u003c ranges.length; i++) {\n Logger.log(ranges[i].getA1Notation());\n}\n```\n\n#### Return\n\n\n[Range[]](/apps-script/reference/spreadsheet/range) --- The ranges to which this conditional format rule is applied."]]