Class GradientCondition
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
สภาพการไล่ระดับสี
เข้าถึงเงื่อนไขการไล่ระดับ (สี) ใน ConditionalFormatRuleApis
กฎการจัดรูปแบบตามเงื่อนไขแต่ละข้ออาจมีเงื่อนไขการไล่ระดับสีเดียว เงื่อนไขการไล่ระดับสี
กำหนดโดยจุด 3 จุดตามสเกลตัวเลข (ต่ำสุด กลาง และสูงสุด) ซึ่งแต่ละจุดจะมีสี
ค่า และInterpolationType
เนื้อหาของเซลล์จะ
เปรียบเทียบกับค่าในมาตราส่วนตัวเลข และสีที่ใช้กับเซลล์จะได้รับการประมาณค่า
โดยอิงตามความใกล้เคียงของเนื้อหาเซลล์กับจุดต่ำสุด กลาง และสูงสุดของเงื่อนไขการไล่ระดับสี
// Logs all the information inside gradient conditional format rules on a sheet.
// The below snippet assumes all colors have ColorType.RGB.
const sheet = SpreadsheetApp.getActiveSheet();
const rules = sheet.getConditionalFormatRules();
for (let i = 0; i < rules.length; i++) {
const gradient = rules[i].getGradientCondition();
const minColor = gradient.getMinColorObject().asRgbColor().asHexString();
const minType = gradient.getMinType();
const minValue = gradient.getMinValue();
const midColor = gradient.getMidColorObject().asRgbColor().asHexString();
const midType = gradient.getMidType();
const midValue = gradient.getMidValue();
const maxColor = gradient.getMaxColorObject().asRgbColor().asHexString();
const maxType = gradient.getMaxType();
const maxValue = gradient.getMaxValue();
Logger.log(`The conditional format gradient information for rule ${i}:
MinColor ${minColor}, MinType ${minType}, MinValue ${minValue},
MidColor ${midColor}, MidType ${midType}, MidValue ${midValue},
MaxColor ${maxColor}, MaxType ${maxType}, MaxValue ${maxValue}`);
}
วิธีการที่เลิกใช้งานแล้ว
วิธีการ | ประเภทการแสดงผล | รายละเอียดแบบย่อ |
getMaxColor()
| String | รับชุดสีสำหรับค่าสูงสุดของเงื่อนไขการไล่ระดับสีนี้ |
getMidColor()
| String | รับชุดสีสำหรับค่าจุดกึ่งกลางของเงื่อนไขการไล่ระดับสีนี้ |
getMinColor()
| String | รับสีที่ตั้งไว้สำหรับค่าต่ำสุดของเงื่อนไขการไล่ระดับสีนี้ |
เอกสารโดยละเอียด
getMaxColorObject()
รับชุดสีสำหรับค่าสูงสุดของเงื่อนไขการไล่ระดับสีนี้ แสดงผล null
หากไม่ได้ตั้งค่าสี
รีเทิร์น
Color
— สีที่ตั้งค่าสำหรับค่าสูงสุดของเงื่อนไขการไล่ระดับสีนี้หรือ null
getMaxType()
รับประเภทการประมาณค่าสำหรับค่าสูงสุดของเงื่อนไขการไล่ระดับสีนี้ แสดงผล null
หากไม่ได้ตั้งค่าประเภทสูงสุดของการไล่ระดับสี
รีเทิร์น
InterpolationType
— ประเภทการประมาณค่าสำหรับค่าสูงสุดของเงื่อนไขการไล่ระดับสีนี้หรือ null
getMaxValue()
รับค่าสูงสุดของเงื่อนไขการไล่ระดับสีนี้ แสดงผลสตริงว่างหาก InterpolationType
เป็น MAX
หรือหากไม่ได้ตั้งค่าสูงสุด
รีเทิร์น
String
— ค่าสูงสุดหากระบุ หรือสตริงว่าง
getMidColorObject()
รับชุดสีสำหรับค่าจุดกึ่งกลางของเงื่อนไขการไล่ระดับสีนี้ แสดงผล null
หากไม่ได้ตั้งค่าสี
รีเทิร์น
Color
— สีที่ตั้งค่าสำหรับค่ากลางของเงื่อนไขการไล่ระดับสีนี้หรือ null
getMidType()
รับประเภทการประมาณค่าสำหรับค่าจุดกึ่งกลางของเงื่อนไขการไล่ระดับสีนี้ แสดงผล null
หากไม่ได้ตั้งค่าประเภทกลางของการไล่ระดับสี
รีเทิร์น
InterpolationType
— ประเภทการประมาณค่าสำหรับค่าจุดกึ่งกลางของเงื่อนไขการไล่ระดับสีนี้หรือ null
getMidValue()
รับค่ากึ่งกลางของเงื่อนไขการไล่ระดับสีนี้ แสดงผลสตริงว่างหากไม่ได้ตั้งค่ากลางของ
การไล่ระดับสี
รีเทิร์น
String
— ค่ากึ่งกลางหรือสตริงว่าง
getMinColorObject()
รับสีที่ตั้งไว้สำหรับค่าต่ำสุดของเงื่อนไขการไล่ระดับสีนี้ แสดงผล null
หากไม่ได้ตั้งค่าสี
รีเทิร์น
Color
— สีที่ตั้งค่าสำหรับค่าต่ำสุดของเงื่อนไขการไล่ระดับสีนี้หรือ null
getMinType()
รับประเภทการประมาณค่าสำหรับค่าต่ำสุดของเงื่อนไขการไล่ระดับสีนี้ แสดง null
หากไม่ได้ตั้งค่าประเภทการไล่ระดับสีต่ำสุด
รีเทิร์น
InterpolationType
— ประเภทการประมาณค่าสำหรับค่าต่ำสุดของเงื่อนไขการไล่ระดับสีนี้หรือ null
getMinValue()
รับค่าต่ำสุดของเงื่อนไขการไล่ระดับสีนี้ แสดงผลสตริงว่างหาก InterpolationType
เป็น MIN
หรือหากไม่ได้ตั้งค่าต่ำสุด
รีเทิร์น
String
— ค่าต่ำสุดหากระบุไว้ หรือสตริงว่าง
วิธีการที่เลิกใช้งานแล้ว
getMaxColor()
เลิกใช้งานแล้ว แทนที่โดย getMaxColorObject()
รับชุดสีสำหรับค่าสูงสุดของเงื่อนไขการไล่ระดับสีนี้ แสดงผลสตริงว่างหาก
ไม่ได้ตั้งค่าสี
รีเทิร์น
String
— สีที่ตั้งค่าสำหรับค่าสูงสุดของเงื่อนไขการไล่ระดับสีนี้หรือสตริงว่าง
getMidColor()
เลิกใช้งานแล้ว แทนที่โดย getMidColorObject()
รับชุดสีสำหรับค่าจุดกึ่งกลางของเงื่อนไขการไล่ระดับสีนี้ แสดงผลสตริงว่าง
หากไม่ได้ตั้งค่าสี
รีเทิร์น
String
— สีที่ตั้งค่าสำหรับค่ากลางของเงื่อนไขการไล่ระดับสีนี้หรือสตริงว่าง
getMinColor()
เลิกใช้งานแล้ว แทนที่โดย getMinColorObject()
รับสีที่ตั้งไว้สำหรับค่าต่ำสุดของเงื่อนไขการไล่ระดับสีนี้ แสดงผลสตริงว่างหาก
ไม่ได้ตั้งค่าสี
รีเทิร์น
String
— สีที่ตั้งค่าไว้สำหรับค่าต่ำสุดของเงื่อนไขการไล่ระดับสีนี้หรือสตริงว่าง
เนื้อหาของหน้าเว็บนี้ได้รับอนุญาตภายใต้ใบอนุญาตที่ต้องระบุที่มาของครีเอทีฟคอมมอนส์ 4.0 และตัวอย่างโค้ดได้รับอนุญาตภายใต้ใบอนุญาต Apache 2.0 เว้นแต่จะระบุไว้เป็นอย่างอื่น โปรดดูรายละเอียดที่นโยบายเว็บไซต์ Google Developers Java เป็นเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-08-05 UTC
[null,null,["อัปเดตล่าสุด 2025-08-05 UTC"],[[["\u003cp\u003eGradient conditions in Google Sheets allow you to apply color scales to cells based on their values, interpolating colors between minimum, midpoint, and maximum points.\u003c/p\u003e\n"],["\u003cp\u003eEach gradient condition is defined by three points (min, mid, max), each having a color, value, and interpolation type.\u003c/p\u003e\n"],["\u003cp\u003eYou can access and manipulate gradient conditions programmatically using Apps Script methods like \u003ccode\u003egetMinColorObject()\u003c/code\u003e, \u003ccode\u003egetMidValue()\u003c/code\u003e, and \u003ccode\u003egetMaxType()\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eDeprecated methods like \u003ccode\u003egetMinColor()\u003c/code\u003e, \u003ccode\u003egetMidColor()\u003c/code\u003e, and \u003ccode\u003egetMaxColor()\u003c/code\u003e have been replaced by object-based alternatives for color retrieval.\u003c/p\u003e\n"]]],["Gradient conditions, within conditional format rules, define cell colors based on a number scale with minimum, midpoint, and maximum values. Each point has a color, value, and interpolation type. Methods like `getMinColorObject()`, `getMidType()`, and `getMaxValue()` retrieve these attributes. Cell content is compared to these values to interpolate and apply a corresponding color. Deprecated methods (`getMinColor()`, `getMidColor()`, `getMaxColor()`) are replaced with `get[Point]ColorObject()`.\n"],null,["# Class GradientCondition\n\nGradientCondition\n\nAccess gradient (color) conditions in [ConditionalFormatRuleApis](/apps-script/reference/spreadsheet/conditional-format-rule).\nEach conditional format rule may contain a single gradient condition. A gradient condition is\ndefined by three points along a number scale (min, mid, and max), each of which has a color, a\nvalue, and a [InterpolationType](/apps-script/reference/spreadsheet/interpolation-type). The content of a cell is\ncompared to the values in the number scale and the color applied to the cell is interpolated\nbased on the cell content's proximity to the gradient condition min, mid, and max points.\n\n```javascript\n// Logs all the information inside gradient conditional format rules on a sheet.\n// The below snippet assumes all colors have ColorType.RGB.\nconst sheet = SpreadsheetApp.getActiveSheet();\nconst rules = sheet.getConditionalFormatRules();\nfor (let i = 0; i \u003c rules.length; i++) {\n const gradient = rules[i].getGradientCondition();\n\n const minColor = gradient.getMinColorObject().asRgbColor().asHexString();\n const minType = gradient.getMinType();\n const minValue = gradient.getMinValue();\n const midColor = gradient.getMidColorObject().asRgbColor().asHexString();\n const midType = gradient.getMidType();\n const midValue = gradient.getMidValue();\n const maxColor = gradient.getMaxColorObject().asRgbColor().asHexString();\n const maxType = gradient.getMaxType();\n const maxValue = gradient.getMaxValue();\n\n Logger.log(`The conditional format gradient information for rule ${i}:\n MinColor ${minColor}, MinType ${minType}, MinValue ${minValue},\n MidColor ${midColor}, MidType ${midType}, MidValue ${midValue},\n MaxColor ${maxColor}, MaxType ${maxType}, MaxValue ${maxValue}`);\n}\n``` \n\n### Methods\n\n| Method | Return type | Brief description |\n|---------------------------------------------|----------------------------------------------------------------------------|--------------------------------------------------------------------------------|\n| [getMaxColorObject()](#getMaxColorObject()) | [Color](/apps-script/reference/spreadsheet/color) | Gets the color set for the maximum value of this gradient condition. |\n| [getMaxType()](#getMaxType()) | [InterpolationType](/apps-script/reference/spreadsheet/interpolation-type) | Gets the interpolation type for the maximum value of this gradient condition. |\n| [getMaxValue()](#getMaxValue()) | `String` | Gets the max value of this gradient condition. |\n| [getMidColorObject()](#getMidColorObject()) | [Color](/apps-script/reference/spreadsheet/color) | Gets the color set for the midpoint value of this gradient condition. |\n| [getMidType()](#getMidType()) | [InterpolationType](/apps-script/reference/spreadsheet/interpolation-type) | Gets the interpolation type for the midpoint value of this gradient condition. |\n| [getMidValue()](#getMidValue()) | `String` | Gets the midpoint value of this gradient condition. |\n| [getMinColorObject()](#getMinColorObject()) | [Color](/apps-script/reference/spreadsheet/color) | Gets the color set for the minimum value of this gradient condition. |\n| [getMinType()](#getMinType()) | [InterpolationType](/apps-script/reference/spreadsheet/interpolation-type) | Gets the interpolation type for the minimum value of this gradient condition. |\n| [getMinValue()](#getMinValue()) | `String` | Gets the minimum value of this gradient condition. |\n\n### Deprecated methods\n\n| Method | Return type | Brief description |\n|---------------------------------|-------------|-----------------------------------------------------------------------|\n| [getMaxColor()](#getMaxColor()) | `String` | Gets the color set for the maximum value of this gradient condition. |\n| [getMidColor()](#getMidColor()) | `String` | Gets the color set for the midpoint value of this gradient condition. |\n| [getMinColor()](#getMinColor()) | `String` | Gets the color set for the minimum value of this gradient condition. |\n\nDetailed documentation\n----------------------\n\n### `get``Max``Color``Object()`\n\nGets the color set for the maximum value of this gradient condition. Returns `null` if\nthe color hasn't been set.\n\n#### Return\n\n\n[Color](/apps-script/reference/spreadsheet/color) --- The color set for the maximum value of this gradient condition or `null`.\n\n*** ** * ** ***\n\n### `get``Max``Type()`\n\nGets the interpolation type for the maximum value of this gradient condition. Returns `null` if the gradient max type hasn't been set.\n\n#### Return\n\n\n[InterpolationType](/apps-script/reference/spreadsheet/interpolation-type) --- The interpolation type for the maximum value of this gradient condition or `null`.\n\n*** ** * ** ***\n\n### `get``Max``Value()`\n\nGets the max value of this gradient condition. Returns an empty string if the [InterpolationType](/apps-script/reference/spreadsheet/interpolation-type) is `MAX` or if the max value hasn't been\nset.\n\n#### Return\n\n\n`String` --- The maximum value if specified or an empty string.\n\n*** ** * ** ***\n\n### `get``Mid``Color``Object()`\n\nGets the color set for the midpoint value of this gradient condition. Returns `null` if\nthe color hasn't been set.\n\n#### Return\n\n\n[Color](/apps-script/reference/spreadsheet/color) --- The color set for the midpoint value of this gradient condition or `null`.\n\n*** ** * ** ***\n\n### `get``Mid``Type()`\n\nGets the interpolation type for the midpoint value of this gradient condition. Returns `null` if the gradient mid type hasn't been set.\n\n#### Return\n\n\n[InterpolationType](/apps-script/reference/spreadsheet/interpolation-type) --- The interpolation type for the midpoint value of this gradient condition or `null`.\n\n*** ** * ** ***\n\n### `get``Mid``Value()`\n\nGets the midpoint value of this gradient condition. Returns an empty string if the gradient mid\nvalue hasn't been set.\n\n#### Return\n\n\n`String` --- The midpoint value or an empty string.\n\n*** ** * ** ***\n\n### `get``Min``Color``Object()`\n\nGets the color set for the minimum value of this gradient condition. Returns `null` if\nthe color hasn't been set.\n\n#### Return\n\n\n[Color](/apps-script/reference/spreadsheet/color) --- The color set for the minimum value of this gradient condition or `null`.\n\n*** ** * ** ***\n\n### `get``Min``Type()`\n\nGets the interpolation type for the minimum value of this gradient condition. Returns `null` if the gradient min type hasn't been set.\n\n#### Return\n\n\n[InterpolationType](/apps-script/reference/spreadsheet/interpolation-type) --- The interpolation type for the minimum value of this gradient condition or `null`.\n\n*** ** * ** ***\n\n### `get``Min``Value()`\n\nGets the minimum value of this gradient condition. Returns an empty string if the [InterpolationType](/apps-script/reference/spreadsheet/interpolation-type) is `MIN` or if the min value hasn't been\nset.\n\n#### Return\n\n\n`String` --- The minimum value if specified or an empty string.\n\nDeprecated methods\n------------------\n\n### `get``Max``Color()`\n\n\n**Deprecated.** Replaced by [getMaxColorObject()](#getMaxColorObject())\n\nGets the color set for the maximum value of this gradient condition. Returns an empty string if\nthe color hasn't been set.\n\n#### Return\n\n\n`String` --- The color set for the maximum value of this gradient condition or an empty string.\n\n*** ** * ** ***\n\n### `get``Mid``Color()`\n\n\n**Deprecated.** Replaced by [getMidColorObject()](#getMidColorObject())\n\nGets the color set for the midpoint value of this gradient condition. Returns an empty string\nif the color hasn't been set.\n\n#### Return\n\n\n`String` --- The color set for the midpoint value of this gradient condition or an empty string.\n\n*** ** * ** ***\n\n### `get``Min``Color()`\n\n\n**Deprecated.** Replaced by [getMinColorObject()](#getMinColorObject())\n\nGets the color set for the minimum value of this gradient condition. Returns an empty string if\nthe color hasn't been set.\n\n#### Return\n\n\n`String` --- The color set for the minimum value of this gradient condition or an empty string."]]