Class ConditionalFormatRuleBuilder

เครื่องมือสร้างกฎการจัดรูปแบบตามเงื่อนไข

เครื่องมือสร้างกฎการจัดรูปแบบตามเงื่อนไข

// Adds a conditional format rule to a sheet that causes cells in range A1:B3 to // turn red if they contain a number between 1 and 10. const sheet = SpreadsheetApp.getActiveSheet(); const range = sheet.getRange('A1:B3'); const rule = SpreadsheetApp.newConditionalFormatRule()                  .whenNumberBetween(1, 10)                  .setBackground('#FF0000')                  .setRanges([range])                  .build(); const rules = sheet.getConditionalFormatRules(); rules.push(rule); sheet.setConditionalFormatRules(rules);

เมธอด

วิธีการประเภทการแสดงผลรายละเอียดแบบย่อ
build()ConditionalFormatRuleสร้างกฎการจัดรูปแบบตามเงื่อนไขจากการตั้งค่าที่ใช้กับเครื่องมือสร้าง
copy()ConditionalFormatRuleBuilderแสดงค่าที่กำหนดล่วงหน้าของเครื่องมือสร้างกฎพร้อมการตั้งค่าของกฎนี้
getBooleanCondition()BooleanConditionเรียกข้อมูล BooleanCondition ของกฎหากกฎนี้ใช้ เกณฑ์เงื่อนไขบูลีน
getGradientCondition()GradientConditionเรียกข้อมูลGradientConditionของกฎ หากกฎนี้ ใช้เกณฑ์เงื่อนไขแบบไล่ระดับสี
getRanges()Range[]เรียกข้อมูลช่วงที่ใช้กฎการจัดรูปแบบตามเงื่อนไขนี้
setBackground(color)ConditionalFormatRuleBuilderตั้งค่าสีพื้นหลังสำหรับรูปแบบของกฎการจัดรูปแบบตามเงื่อนไข
setBackgroundObject(color)ConditionalFormatRuleBuilderตั้งค่าสีพื้นหลังสำหรับรูปแบบของกฎการจัดรูปแบบตามเงื่อนไข
setBold(bold)ConditionalFormatRuleBuilderตั้งค่าการทำข้อความเป็นตัวหนาสำหรับรูปแบบของกฎการจัดรูปแบบตามเงื่อนไข
setFontColor(color)ConditionalFormatRuleBuilderกำหนดสีแบบอักษรให้กับรูปแบบของกฎการจัดรูปแบบตามเงื่อนไข
setFontColorObject(color)ConditionalFormatRuleBuilderกำหนดสีแบบอักษรให้กับรูปแบบของกฎการจัดรูปแบบตามเงื่อนไข
setGradientMaxpoint(color)ConditionalFormatRuleBuilderล้างค่าจุดสูงสุดของการไล่ระดับสีของกฎการจัดรูปแบบตามเงื่อนไข และใช้ค่าสูงสุด ในช่วงของกฎแทน
setGradientMaxpointObject(color)ConditionalFormatRuleBuilderล้างค่าจุดสูงสุดของการไล่ระดับสีของกฎการจัดรูปแบบตามเงื่อนไข และใช้ค่าสูงสุด ในช่วงของกฎแทน
setGradientMaxpointObjectWithValue(color, type, value)ConditionalFormatRuleBuilderตั้งค่าฟิลด์จุดสูงสุดของการไล่ระดับสีของกฎการจัดรูปแบบตามเงื่อนไข
setGradientMaxpointWithValue(color, type, value)ConditionalFormatRuleBuilderตั้งค่าฟิลด์จุดสูงสุดของการไล่ระดับสีของกฎการจัดรูปแบบตามเงื่อนไข
setGradientMidpointObjectWithValue(color, type, value)ConditionalFormatRuleBuilderตั้งค่าฟิลด์จุดกึ่งกลางของการไล่ระดับสีของกฎการจัดรูปแบบตามเงื่อนไข
setGradientMidpointWithValue(color, type, value)ConditionalFormatRuleBuilderตั้งค่าฟิลด์จุดกึ่งกลางของการไล่ระดับสีของกฎการจัดรูปแบบตามเงื่อนไข
setGradientMinpoint(color)ConditionalFormatRuleBuilderล้างค่าจุดต่ำสุดของเส้นไล่ระดับสีของกฎการจัดรูปแบบตามเงื่อนไข และใช้ค่าต่ำสุด ในขอบเขตของกฎแทน
setGradientMinpointObject(color)ConditionalFormatRuleBuilderล้างค่าจุดต่ำสุดของเส้นไล่ระดับสีของกฎการจัดรูปแบบตามเงื่อนไข และใช้ค่าต่ำสุด ในขอบเขตของกฎแทน
setGradientMinpointObjectWithValue(color, type, value)ConditionalFormatRuleBuilderตั้งค่าฟิลด์จุดต่ำสุดของเส้นไล่ระดับของกฎการจัดรูปแบบตามเงื่อนไข
setGradientMinpointWithValue(color, type, value)ConditionalFormatRuleBuilderตั้งค่าฟิลด์จุดต่ำสุดของเส้นไล่ระดับของกฎการจัดรูปแบบตามเงื่อนไข
setItalic(italic)ConditionalFormatRuleBuilderกำหนดให้ข้อความเป็นตัวเอียงสำหรับรูปแบบของกฎการจัดรูปแบบตามเงื่อนไข
setRanges(ranges)ConditionalFormatRuleBuilderตั้งค่าช่วงอย่างน้อย 1 ช่วงที่จะใช้กฎการจัดรูปแบบตามเงื่อนไขนี้
setStrikethrough(strikethrough)ConditionalFormatRuleBuilderกำหนดขีดทับข้อความสำหรับรูปแบบของกฎการจัดรูปแบบตามเงื่อนไข
setUnderline(underline)ConditionalFormatRuleBuilderกำหนดการขีดเส้นใต้ข้อความสำหรับรูปแบบของกฎการจัดรูปแบบตามเงื่อนไข
whenCellEmpty()ConditionalFormatRuleBuilderตั้งค่ากฎการจัดรูปแบบตามเงื่อนไขให้ทริกเกอร์เมื่อเซลล์ว่าง
whenCellNotEmpty()ConditionalFormatRuleBuilderตั้งค่ากฎการจัดรูปแบบตามเงื่อนไขให้ทริกเกอร์เมื่อเซลล์ไม่ว่าง
whenDateAfter(date)ConditionalFormatRuleBuilderตั้งค่ากฎการจัดรูปแบบตามเงื่อนไขให้ทริกเกอร์เมื่อวันที่อยู่หลังค่าที่ระบุ
whenDateAfter(date)ConditionalFormatRuleBuilderตั้งค่ากฎการจัดรูปแบบตามเงื่อนไขให้ทริกเกอร์เมื่อวันที่อยู่หลังวันที่สัมพัทธ์ที่ระบุ
whenDateBefore(date)ConditionalFormatRuleBuilderตั้งค่ากฎการจัดรูปแบบตามเงื่อนไขให้ทริกเกอร์เมื่อวันที่อยู่ก่อนวันที่ที่ระบุ
whenDateBefore(date)ConditionalFormatRuleBuilderตั้งค่ากฎการจัดรูปแบบตามเงื่อนไขให้ทริกเกอร์เมื่อวันที่อยู่ก่อนวันที่สัมพัทธ์ที่ระบุ
whenDateEqualTo(date)ConditionalFormatRuleBuilderตั้งค่ากฎการจัดรูปแบบตามเงื่อนไขให้ทริกเกอร์เมื่อวันที่เท่ากับวันที่ที่ระบุ
whenDateEqualTo(date)ConditionalFormatRuleBuilderตั้งค่ากฎการจัดรูปแบบตามเงื่อนไขให้ทริกเกอร์เมื่อวันที่เท่ากับวันที่สัมพัทธ์ที่ระบุ
whenFormulaSatisfied(formula)ConditionalFormatRuleBuilderกำหนดกฎการจัดรูปแบบตามเงื่อนไขให้ทริกเกอร์เมื่อสูตรที่ระบุให้ค่าเป็น true
whenNumberBetween(start, end)ConditionalFormatRuleBuilderตั้งค่ากฎการจัดรูปแบบตามเงื่อนไขให้ทริกเกอร์เมื่อตัวเลขอยู่ระหว่างหรือเป็นค่าใดค่าหนึ่งของค่าที่ระบุ 2 ค่า
whenNumberEqualTo(number)ConditionalFormatRuleBuilderตั้งค่ากฎการจัดรูปแบบตามเงื่อนไขให้ทริกเกอร์เมื่อตัวเลขเท่ากับค่าที่ระบุ
whenNumberGreaterThan(number)ConditionalFormatRuleBuilderกำหนดกฎการจัดรูปแบบตามเงื่อนไขให้ทริกเกอร์เมื่อตัวเลขมากกว่าค่าที่ระบุ
whenNumberGreaterThanOrEqualTo(number)ConditionalFormatRuleBuilderตั้งค่ากฎการจัดรูปแบบตามเงื่อนไขให้ทริกเกอร์เมื่อตัวเลขมากกว่าหรือเท่ากับค่าที่ระบุ
whenNumberLessThan(number)ConditionalFormatRuleBuilderตั้งค่ากฎการจัดรูปแบบตามเงื่อนไขให้ทริกเกอร์เมื่อตัวเลขน้อยกว่าค่าที่ระบุ
whenNumberLessThanOrEqualTo(number)ConditionalFormatRuleBuilderตั้งค่ากฎการจัดรูปแบบตามเงื่อนไขให้ทริกเกอร์เมื่อตัวเลขน้อยกว่าหรือเท่ากับค่าที่ระบุ
whenNumberNotBetween(start, end)ConditionalFormatRuleBuilderตั้งค่ากฎการจัดรูปแบบตามเงื่อนไขให้ทริกเกอร์เมื่อตัวเลขไม่ได้อยู่ระหว่างค่าที่ระบุ 2 ค่า และไม่ใช่ค่าใดค่าหนึ่ง
whenNumberNotEqualTo(number)ConditionalFormatRuleBuilderกำหนดกฎการจัดรูปแบบตามเงื่อนไขให้ทริกเกอร์เมื่อตัวเลขไม่เท่ากับค่าที่ระบุ
whenTextContains(text)ConditionalFormatRuleBuilderตั้งค่ากฎการจัดรูปแบบตามเงื่อนไขให้ทริกเกอร์เมื่ออินพุตมีค่าที่ระบุ
whenTextDoesNotContain(text)ConditionalFormatRuleBuilderตั้งค่ากฎการจัดรูปแบบตามเงื่อนไขให้ทริกเกอร์เมื่ออินพุตไม่มีค่าที่ระบุ
whenTextEndsWith(text)ConditionalFormatRuleBuilderตั้งค่ากฎการจัดรูปแบบตามเงื่อนไขให้ทริกเกอร์เมื่ออินพุตลงท้ายด้วยค่าที่ระบุ
whenTextEqualTo(text)ConditionalFormatRuleBuilderตั้งค่ากฎการจัดรูปแบบตามเงื่อนไขให้ทริกเกอร์เมื่ออินพุตเท่ากับค่าที่ระบุ
whenTextStartsWith(text)ConditionalFormatRuleBuilderตั้งค่ากฎการจัดรูปแบบตามเงื่อนไขให้ทริกเกอร์เมื่ออินพุตเริ่มต้นด้วยค่าที่ระบุ
withCriteria(criteria, args)ConditionalFormatRuleBuilderตั้งค่ากฎการจัดรูปแบบตามเงื่อนไขเป็นเกณฑ์ที่กำหนดโดยค่า BooleanCriteria ซึ่งโดยปกติจะมาจาก criteria และ arguments ของกฎที่มีอยู่

เอกสารโดยละเอียด

build()

สร้างกฎการจัดรูปแบบตามเงื่อนไขจากการตั้งค่าที่ใช้กับเครื่องมือสร้าง

รีเทิร์น

ConditionalFormatRule — การแสดงกฎการจัดรูปแบบตามเงื่อนไข


copy()

แสดงค่าที่กำหนดล่วงหน้าของเครื่องมือสร้างกฎพร้อมการตั้งค่าของกฎนี้

รีเทิร์น

ConditionalFormatRuleBuilder - ตัวสร้างที่อิงตามการตั้งค่าของกฎนี้


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[] — ช่วงที่ใช้กฎการจัดรูปแบบตามเงื่อนไขนี้


setBackground(color)

ตั้งค่าสีพื้นหลังสำหรับรูปแบบของกฎการจัดรูปแบบตามเงื่อนไข การส่ง null จะนำการตั้งค่ารูปแบบสีพื้นหลังออกจากกฎ

// Adds a conditional format rule to a sheet that causes cells in range A1:B3 to // set their background color to red if the cell has text equal to "hello".  const sheet = SpreadsheetApp.getActiveSheet(); const range = sheet.getRange('A1:B3'); const rule = SpreadsheetApp.newConditionalFormatRule()                  .whenTextEqualTo('hello')                  .setBackground('#FF0000')                  .setRanges([range])                  .build(); const rules = sheet.getConditionalFormatRules(); rules.push(rule); sheet.setConditionalFormatRules(rules);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
colorStringสีที่ต้องการหรือ null เพื่อล้าง

รีเทิร์น

ConditionalFormatRuleBuilder — ตัวสร้างสำหรับการเชื่อมโยง


setBackgroundObject(color)

ตั้งค่าสีพื้นหลังสำหรับรูปแบบของกฎการจัดรูปแบบตามเงื่อนไข การส่ง null จะนำการตั้งค่ารูปแบบสีพื้นหลังออกจากกฎ

// Adds a conditional format rule to a sheet that causes cells in range A1:B3 to // set their background color to theme background color if the cell has text // equal to "hello".  const sheet = SpreadsheetApp.getActiveSheet(); const range = sheet.getRange('A1:B3'); const color = SpreadsheetApp.newColor()                   .setThemeColor(SpreadsheetApp.ThemeColorType.BACKGROUND)                   .build(); const rule = SpreadsheetApp.newConditionalFormatRule()                  .whenTextEqualTo('hello')                  .setBackground(color)                  .setRanges([range])                  .build(); const rules = sheet.getConditionalFormatRules(); rules.push(rule); sheet.setConditionalFormatRules(rules);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
colorColorออบเจ็กต์สีที่ต้องการหรือ null เพื่อล้าง

รีเทิร์น

ConditionalFormatRuleBuilder — ตัวสร้างสำหรับการเชื่อมโยง


setBold(bold)

ตั้งค่าการทำข้อความเป็นตัวหนาสำหรับรูปแบบของกฎการจัดรูปแบบตามเงื่อนไข หาก bold เป็น true กฎจะทำตัวอักษรเป็นตัวหนาหากตรงตามเงื่อนไข หากเป็น false กฎจะนำการทำตัวอักษรเป็นตัวหนาที่มีอยู่ออก หากตรงตามเงื่อนไข การส่ง null จะนำการตั้งค่ารูปแบบตัวหนาออกจาก กฎ

// Adds a conditional format rule to a sheet that causes cells in range A1:B3 to // turn their text bold if the cell has text equal to "hello".  const sheet = SpreadsheetApp.getActiveSheet(); const range = sheet.getRange('A1:B3'); const rule = SpreadsheetApp.newConditionalFormatRule()                  .whenTextEqualTo('hello')                  .setBold(true)                  .setRanges([range])                  .build(); const rules = sheet.getConditionalFormatRules(); rules.push(rule); sheet.setConditionalFormatRules(rules);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
boldBooleanจะทำตัวหนาข้อความหรือไม่หากตรงตามเงื่อนไขรูปแบบ null จะนำการตั้งค่านี้ออก

รีเทิร์น

ConditionalFormatRuleBuilder — ตัวสร้างสำหรับการเชื่อมโยง


setFontColor(color)

กำหนดสีแบบอักษรให้กับรูปแบบของกฎการจัดรูปแบบตามเงื่อนไข การส่ง null จะนำ การตั้งค่ารูปแบบสีแบบอักษรออกจากกฎ

// Adds a conditional format rule to a sheet that causes cells in range A1:B3 to // set their font color to red if the cell has text equal to "hello".  const sheet = SpreadsheetApp.getActiveSheet(); const range = sheet.getRange('A1:B3'); const rule = SpreadsheetApp.newConditionalFormatRule()                  .whenTextEqualTo('hello')                  .setFontColor('#FF0000')                  .setRanges([range])                  .build(); const rules = sheet.getConditionalFormatRules(); rules.push(rule); sheet.setConditionalFormatRules(rules);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
colorStringสีที่ต้องการหรือ null เพื่อล้าง

รีเทิร์น

ConditionalFormatRuleBuilder — ตัวสร้างสำหรับการเชื่อมโยง


setFontColorObject(color)

กำหนดสีแบบอักษรให้กับรูปแบบของกฎการจัดรูปแบบตามเงื่อนไข การส่ง null จะนำ การตั้งค่ารูปแบบสีแบบอักษรออกจากกฎ

// Adds a conditional format rule to a sheet that causes cells in range A1:B3 to // set their font color to theme text color if the cell has text equal to // "hello".  const sheet = SpreadsheetApp.getActiveSheet(); const range = sheet.getRange('A1:B3'); const color = SpreadsheetApp.newColor()                   .setThemeColor(SpreadsheetApp.ThemeColorType.TEXT)                   .build(); const rule = SpreadsheetApp.newConditionalFormatRule()                  .whenTextEqualTo('hello')                  .setFontColor(color)                  .setRanges([range])                  .build(); const rules = sheet.getConditionalFormatRules(); rules.push(rule); sheet.setConditionalFormatRules(rules);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
colorColorออบเจ็กต์สีที่ต้องการหรือ null เพื่อล้าง

รีเทิร์น

ConditionalFormatRuleBuilder — ตัวสร้างสำหรับการเชื่อมโยง


setGradientMaxpoint(color)

ล้างค่าจุดสูงสุดของการไล่ระดับสีของกฎการจัดรูปแบบตามเงื่อนไข และใช้ค่าสูงสุด ในช่วงของกฎแทน และยังตั้งค่าสีของจุดสูงสุดของการไล่ระดับสีเป็นสีอินพุตด้วย

// Adds a conditional format rule to a sheet that causes cells in range A1:B3 to // set their background color somewhere between white and red, based on their // values in comparison to the ranges minimum and maximum values.  const sheet = SpreadsheetApp.getActiveSheet(); const range = sheet.getRange('A1:B3'); const rule = SpreadsheetApp.newConditionalFormatRule()                  .setGradientMaxpoint('#FF0000')                  .setGradientMinpoint('#FFFFFF')                  .setRanges([range])                  .build(); const rules = sheet.getConditionalFormatRules(); rules.push(rule); sheet.setConditionalFormatRules(rules);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
colorStringสีของค่าสูงสุดที่จะตั้ง

รีเทิร์น

ConditionalFormatRuleBuilder — ตัวสร้างสำหรับการเชื่อมโยง


setGradientMaxpointObject(color)

ล้างค่าจุดสูงสุดของการไล่ระดับสีของกฎการจัดรูปแบบตามเงื่อนไข และใช้ค่าสูงสุด ในช่วงของกฎแทน และยังตั้งค่าสีของจุดสูงสุดของการไล่ระดับสีเป็นสีอินพุตด้วย

// Adds a conditional format rule to a sheet that causes cells in range A1:B3 to // set their background color somewhere between theme text and background // colors, based on their values in comparison to the ranges minimum and maximum // values.  const sheet = SpreadsheetApp.getActiveSheet(); const range = sheet.getRange('A1:B3'); const textColor = SpreadsheetApp.newColor()                       .setThemeColor(SpreadsheetApp.ThemeColorType.TEXT)                       .build(); const backgroundColor =     SpreadsheetApp.newColor()         .setThemeColor(SpreadsheetApp.ThemeColorType.BACKGROUND)         .build(); const rule = SpreadsheetApp.newConditionalFormatRule()                  .setGradientMaxpoint(textColor)                  .setGradientMinpoint(backgroundColor)                  .setRanges([range])                  .build(); const rules = sheet.getConditionalFormatRules(); rules.push(rule); sheet.setConditionalFormatRules(rules);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
colorColorออบเจ็กต์สีของค่าสูงสุดที่จะตั้งค่า

รีเทิร์น

ConditionalFormatRuleBuilder — ตัวสร้างสำหรับการเชื่อมโยง


setGradientMaxpointObjectWithValue(color, type, value)

ตั้งค่าฟิลด์จุดสูงสุดของการไล่ระดับสีของกฎการจัดรูปแบบตามเงื่อนไข

// Adds a conditional format rule to a sheet that causes cells in range A1:B3 to // set their background color somewhere from theme accent 1, accent 2 to accent // 3 colors, based on their values in comparison to the values 0, 50, and 100.  const sheet = SpreadsheetApp.getActiveSheet(); const range = sheet.getRange('A1:B3'); const color1 = SpreadsheetApp.newColor()                    .setThemeColor(SpreadsheetApp.ThemeColorType.ACCENT1)                    .build(); const color2 = SpreadsheetApp.newColor()                    .setThemeColor(SpreadsheetApp.ThemeColorType.ACCENT2)                    .build(); const color3 = SpreadsheetApp.newColor()                    .setThemeColor(SpreadsheetApp.ThemeColorType.ACCENT3)                    .build(); const rule = SpreadsheetApp.newConditionalFormatRule()                  .setGradientMaxpointWithValue(                      color1,                      SpreadsheetApp.InterpolationType.NUMBER,                      '100',                      )                  .setGradientMidpointWithValue(                      color2,                      SpreadsheetApp.InterpolationType.NUMBER,                      '50',                      )                  .setGradientMinpointWithValue(                      color3,                      SpreadsheetApp.InterpolationType.NUMBER,                      '0',                      )                  .setRanges([range])                  .build(); const rules = sheet.getConditionalFormatRules(); rules.push(rule); sheet.setConditionalFormatRules(rules);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
colorColorสีของค่าสูงสุดที่จะตั้ง
typeInterpolationTypeประเภทการประมาณค่าสูงสุดที่จะตั้งค่า
valueStringค่าสูงสุดที่จะตั้ง

รีเทิร์น

ConditionalFormatRuleBuilder — ตัวสร้างสำหรับการเชื่อมโยง


setGradientMaxpointWithValue(color, type, value)

ตั้งค่าฟิลด์จุดสูงสุดของการไล่ระดับสีของกฎการจัดรูปแบบตามเงื่อนไข

// Adds a conditional format rule to a sheet that causes cells in range A1:B3 to // set their background color somewhere from red green to blue, based on their // values in comparison to the values 0, 50, and 100.  const sheet = SpreadsheetApp.getActiveSheet(); const range = sheet.getRange('A1:B3'); const rule = SpreadsheetApp.newConditionalFormatRule()                  .setGradientMaxpointWithValue(                      '#0000FF',                      SpreadsheetApp.InterpolationType.NUMBER,                      '100',                      )                  .setGradientMidpointWithValue(                      '#00FF00',                      SpreadsheetApp.InterpolationType.NUMBER,                      '50',                      )                  .setGradientMinpointWithValue(                      '#FF0000',                      SpreadsheetApp.InterpolationType.NUMBER,                      '0',                      )                  .setRanges([range])                  .build(); const rules = sheet.getConditionalFormatRules(); rules.push(rule); sheet.setConditionalFormatRules(rules);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
colorStringสีของค่าสูงสุดที่จะตั้ง
typeInterpolationTypeประเภทการประมาณค่าสูงสุดที่จะตั้งค่า
valueStringค่าสูงสุดที่จะตั้ง

รีเทิร์น

ConditionalFormatRuleBuilder — ตัวสร้างสำหรับการเชื่อมโยง


setGradientMidpointObjectWithValue(color, type, value)

ตั้งค่าฟิลด์จุดกึ่งกลางของการไล่ระดับสีของกฎการจัดรูปแบบตามเงื่อนไข ล้างฟิลด์จุดกึ่งกลางทั้งหมด หากประเภทการประมาณค่าที่ส่งผ่านคือ null

// Adds a conditional format rule to a sheet that causes cells in range A1:B3 to // set their background color somewhere from theme accent 1 to accent 2 to // accent 3 colors, based on their values in comparison to the values 0, 50, and // 100.  const sheet = SpreadsheetApp.getActiveSheet(); const range = sheet.getRange('A1:B3'); const color1 = SpreadsheetApp.newColor()                    .setThemeColor(SpreadsheetApp.ThemeColorType.ACCENT1)                    .build(); const color2 = SpreadsheetApp.newColor()                    .setThemeColor(SpreadsheetApp.ThemeColorType.ACCENT2)                    .build(); const color3 = SpreadsheetApp.newColor()                    .setThemeColor(SpreadsheetApp.ThemeColorType.ACCENT3)                    .build(); const rule = SpreadsheetApp.newConditionalFormatRule()                  .setGradientMaxpointWithValue(                      color1,                      SpreadsheetApp.InterpolationType.NUMBER,                      '100',                      )                  .setGradientMidpointWithValue(                      color2,                      SpreadsheetApp.InterpolationType.NUMBER,                      '50',                      )                  .setGradientMinpointWithValue(                      color3,                      SpreadsheetApp.InterpolationType.NUMBER,                      '0',                      )                  .setRanges([range])                  .build(); const rules = sheet.getConditionalFormatRules(); rules.push(rule); sheet.setConditionalFormatRules(rules);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
colorColorสีจุดกึ่งกลางที่จะตั้งค่า
typeInterpolationTypeประเภทการประมาณค่ากึ่งกลางที่จะตั้งค่าหรือ null เพื่อล้าง
valueStringค่ากลางที่จะตั้ง

รีเทิร์น

ConditionalFormatRuleBuilder — ตัวสร้างสำหรับการเชื่อมโยง


setGradientMidpointWithValue(color, type, value)

ตั้งค่าฟิลด์จุดกึ่งกลางของการไล่ระดับสีของกฎการจัดรูปแบบตามเงื่อนไข ล้างฟิลด์จุดกึ่งกลางทั้งหมด หากประเภทการประมาณค่าที่ส่งผ่านคือ null

// Adds a conditional format rule to a sheet that causes cells in range A1:B3 to // set their background color somewhere from red green to blue, based on their // values in comparison to the values 0, 50, and 100.  const sheet = SpreadsheetApp.getActiveSheet(); const range = sheet.getRange('A1:B3'); const rule = SpreadsheetApp.newConditionalFormatRule()                  .setGradientMaxpointWithValue(                      '#0000FF',                      SpreadsheetApp.InterpolationType.NUMBER,                      '100',                      )                  .setGradientMidpointWithValue(                      '#00FF00',                      SpreadsheetApp.InterpolationType.NUMBER,                      '50',                      )                  .setGradientMinpointWithValue(                      '#FF0000',                      SpreadsheetApp.InterpolationType.NUMBER,                      '0',                      )                  .setRanges([range])                  .build(); const rules = sheet.getConditionalFormatRules(); rules.push(rule); sheet.setConditionalFormatRules(rules);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
colorStringสีจุดกึ่งกลางที่จะตั้งค่า
typeInterpolationTypeประเภทการประมาณค่ากึ่งกลางที่จะตั้งค่าหรือ null เพื่อล้าง
valueStringค่ากลางที่จะตั้ง

รีเทิร์น

ConditionalFormatRuleBuilder — ตัวสร้างสำหรับการเชื่อมโยง


setGradientMinpoint(color)

ล้างค่าจุดต่ำสุดของเส้นไล่ระดับสีของกฎการจัดรูปแบบตามเงื่อนไข และใช้ค่าต่ำสุด ในขอบเขตของกฎแทน และยังตั้งค่าสีของจุดต่ำสุดของการไล่ระดับสีเป็นสีที่ป้อนด้วย

// Adds a conditional format rule to a sheet that causes cells in range A1:B3 to // set their background color somewhere between white and red, based on their // values in comparison to the ranges minimum and maximum values.  const sheet = SpreadsheetApp.getActiveSheet(); const range = sheet.getRange('A1:B3'); const rule = SpreadsheetApp.newConditionalFormatRule()                  .setGradientMaxpoint('#FF0000')                  .setGradientMinpoint('#FFFFFF')                  .setRanges([range])                  .build(); const rules = sheet.getConditionalFormatRules(); rules.push(rule); sheet.setConditionalFormatRules(rules);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
colorStringสีของจุดต่ำสุดที่จะตั้งค่า

รีเทิร์น

ConditionalFormatRuleBuilder — ตัวสร้างสำหรับการเชื่อมโยง


setGradientMinpointObject(color)

ล้างค่าจุดต่ำสุดของเส้นไล่ระดับสีของกฎการจัดรูปแบบตามเงื่อนไข และใช้ค่าต่ำสุด ในขอบเขตของกฎแทน และยังตั้งค่าสีของจุดต่ำสุดของการไล่ระดับสีเป็นสีที่ป้อนด้วย

// Adds a conditional format rule to a sheet that causes cells in range A1:B3 to // set their background color somewhere between theme text and background // colors, based on their values in comparison to the ranges minimum and maximum // values.  const sheet = SpreadsheetApp.getActiveSheet(); const range = sheet.getRange('A1:B3'); const textColor = SpreadsheetApp.newColor()                       .setThemeColor(SpreadsheetApp.ThemeColorType.TEXT)                       .build(); const backgroundColor =     SpreadsheetApp.newColor()         .setThemeColor(SpreadsheetApp.ThemeColorType.BACKGROUND)         .build(); const rule = SpreadsheetApp.newConditionalFormatRule()                  .setGradientMaxpoint(textColor)                  .setGradientMinpoint(backgroundColor)                  .setRanges([range])                  .build(); const rules = sheet.getConditionalFormatRules(); rules.push(rule); sheet.setConditionalFormatRules(rules);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
colorColorออบเจ็กต์สีของจุดต่ำสุดที่จะตั้งค่า

รีเทิร์น

ConditionalFormatRuleBuilder — ตัวสร้างสำหรับการเชื่อมโยง


setGradientMinpointObjectWithValue(color, type, value)

ตั้งค่าฟิลด์จุดต่ำสุดของเส้นไล่ระดับของกฎการจัดรูปแบบตามเงื่อนไข

// Adds a conditional format rule to a sheet that causes cells in range A1:B3 to // set their background color somewhere from theme accent 1 to accent 2 to // accent 3 colors, based on their values in comparison to the values 0, 50, and // 100.  const sheet = SpreadsheetApp.getActiveSheet(); const range = sheet.getRange('A1:B3'); const color1 = SpreadsheetApp.newColor()                    .setThemeColor(SpreadsheetApp.ThemeColorType.ACCENT1)                    .build(); const color2 = SpreadsheetApp.newColor()                    .setThemeColor(SpreadsheetApp.ThemeColorType.ACCENT2)                    .build(); const color3 = SpreadsheetApp.newColor()                    .setThemeColor(SpreadsheetApp.ThemeColorType.ACCENT3)                    .build(); const rule = SpreadsheetApp.newConditionalFormatRule()                  .setGradientMaxpointWithValue(                      color1,                      SpreadsheetApp.InterpolationType.NUMBER,                      '100',                      )                  .setGradientMidpointWithValue(                      color2,                      SpreadsheetApp.InterpolationType.NUMBER,                      '50',                      )                  .setGradientMinpointWithValue(                      color3,                      SpreadsheetApp.InterpolationType.NUMBER,                      '0',                      )                  .setRanges([range])                  .build(); const rules = sheet.getConditionalFormatRules(); rules.push(rule); sheet.setConditionalFormatRules(rules);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
colorColorสีของจุดต่ำสุดที่จะตั้งค่า
typeInterpolationTypeประเภทการประมาณค่า minpoint ที่จะตั้งค่า
valueStringค่าต่ำสุดที่จะตั้ง

รีเทิร์น

ConditionalFormatRuleBuilder — ตัวสร้างสำหรับการเชื่อมโยง


setGradientMinpointWithValue(color, type, value)

ตั้งค่าฟิลด์จุดต่ำสุดของเส้นไล่ระดับของกฎการจัดรูปแบบตามเงื่อนไข

// Adds a conditional format rule to a sheet that causes cells in range A1:B3 to // set their background color somewhere from red to green to blue, based on // their values in comparison to the values 0, 50, and 100.  const sheet = SpreadsheetApp.getActiveSheet(); const range = sheet.getRange('A1:B3'); const rule = SpreadsheetApp.newConditionalFormatRule()                  .setGradientMaxpointWithValue(                      '#0000FF',                      SpreadsheetApp.InterpolationType.NUMBER,                      '100',                      )                  .setGradientMidpointWithValue(                      '#00FF00',                      SpreadsheetApp.InterpolationType.NUMBER,                      '50',                      )                  .setGradientMinpointWithValue(                      '#FF0000',                      SpreadsheetApp.InterpolationType.NUMBER,                      '0',                      )                  .setRanges([range])                  .build(); const rules = sheet.getConditionalFormatRules(); rules.push(rule); sheet.setConditionalFormatRules(rules);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
colorStringสีของจุดต่ำสุดที่จะตั้งค่า
typeInterpolationTypeประเภทการประมาณค่า minpoint ที่จะตั้งค่า
valueStringค่าต่ำสุดที่จะตั้ง

รีเทิร์น

ConditionalFormatRuleBuilder — ตัวสร้างสำหรับการเชื่อมโยง


setItalic(italic)

กำหนดให้ข้อความเป็นตัวเอียงสำหรับรูปแบบของกฎการจัดรูปแบบตามเงื่อนไข หาก italic เป็น true กฎจะทำให้ข้อความเป็นตัวเอียงหากตรงตามเงื่อนไข แต่หากเป็น false กฎจะนำการทำให้เป็นตัวเอียงที่มีอยู่ ออกหากตรงตามเงื่อนไข การส่ง null จะนำการตั้งค่ารูปแบบตัวเอียง ออกจากกฎ

// Adds a conditional format rule to a sheet that causes cells in range A1:B3 to // turn their text italic if the cell has text equal to "hello".  const sheet = SpreadsheetApp.getActiveSheet(); const range = sheet.getRange('A1:B3'); const rule = SpreadsheetApp.newConditionalFormatRule()                  .whenTextEqualTo('hello')                  .setItalic(true)                  .setRanges([range])                  .build(); const rules = sheet.getConditionalFormatRules(); rules.push(rule); sheet.setConditionalFormatRules(rules);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
italicBooleanไม่ว่าจะควรทำตัวเอียงข้อความหรือไม่หากตรงตามเงื่อนไขรูปแบบ null จะนำการตั้งค่านี้ออก

รีเทิร์น

ConditionalFormatRuleBuilder — ตัวสร้างสำหรับการเชื่อมโยง


setRanges(ranges)

ตั้งค่าช่วงอย่างน้อย 1 ช่วงที่จะใช้กฎการจัดรูปแบบตามเงื่อนไขนี้ การดำเนินการนี้ จะแทนที่ช่วงที่มีอยู่ การตั้งค่าอาร์เรย์ว่างจะล้างช่วงที่มีอยู่ กฎต้องมีช่วงอย่างน้อย 1 ช่วง

// Adds a conditional format rule to a sheet that causes cells in range A1:B3 // and range D4:F6 to turn red if they contain a number between 1 and 10. const sheet = SpreadsheetApp.getActiveSheet(); const rangeOne = sheet.getRange('A1:B3'); const rangeTwo = sheet.getRange('D4:F6'); const rule = SpreadsheetApp.newConditionalFormatRule()                  .whenNumberBetween(1, 10)                  .setBackground('#FF0000')                  .setRanges([rangeOne, rangeTwo])                  .build(); const rules = sheet.getConditionalFormatRules(); rules.push(rule); sheet.setConditionalFormatRules(rules);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
rangesRange[]ช่วงที่ใช้กฎการจัดรูปแบบตามเงื่อนไขนี้

รีเทิร์น

ConditionalFormatRuleBuilder — ตัวสร้างสำหรับการเชื่อมโยง


setStrikethrough(strikethrough)

กำหนดขีดทับข้อความสำหรับรูปแบบของกฎการจัดรูปแบบตามเงื่อนไข หาก strikethrough เป็น true กฎจะขีดทับข้อความหากตรงตามเงื่อนไข หากเป็น false กฎจะ นำการจัดรูปแบบขีดทับที่มีอยู่ออกหากตรงตามเงื่อนไข การส่ง null จะนำการตั้งค่ารูปแบบขีดทับออกจากกฎ

// Adds a conditional format rule to a sheet that causes cells in range A1:B3 to // strikethrough their text if the cell has text equal to "hello".  const sheet = SpreadsheetApp.getActiveSheet(); const range = sheet.getRange('A1:B3'); const rule = SpreadsheetApp.newConditionalFormatRule()                  .whenTextEqualTo('hello')                  .setStrikethrough(true)                  .setRanges([range])                  .build(); const rules = sheet.getConditionalFormatRules(); rules.push(rule); sheet.setConditionalFormatRules(rules);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
strikethroughBooleanจะขีดทับข้อความหรือไม่หากตรงตามเงื่อนไขรูปแบบ null จะนำการตั้งค่านี้ออก

รีเทิร์น

ConditionalFormatRuleBuilder — ตัวสร้างสำหรับการเชื่อมโยง


setUnderline(underline)

กำหนดการขีดเส้นใต้ข้อความสำหรับรูปแบบของกฎการจัดรูปแบบตามเงื่อนไข หาก underline เป็น true กฎจะขีดเส้นใต้ข้อความหากตรงตามเงื่อนไข แต่หากเป็น false กฎจะนำเส้นใต้ที่มีอยู่ออกหากตรงตามเงื่อนไข การส่ง null จะนำการตั้งค่ารูปแบบขีดเส้นใต้ ออกจากกฎ

// Adds a conditional format rule to a sheet that causes cells in range A1:B3 to // underline their text if the cell has text equal to "hello".  const sheet = SpreadsheetApp.getActiveSheet(); const range = sheet.getRange('A1:B3'); const rule = SpreadsheetApp.newConditionalFormatRule()                  .whenTextEqualTo('hello')                  .setUnderline(true)                  .setRanges([range])                  .build(); const rules = sheet.getConditionalFormatRules(); rules.push(rule); sheet.setConditionalFormatRules(rules);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
underlineBooleanจะขีดเส้นใต้ข้อความหรือไม่หากตรงตามเงื่อนไขรูปแบบ null จะนำการตั้งค่านี้ออก

รีเทิร์น

ConditionalFormatRuleBuilder — ตัวสร้างสำหรับการเชื่อมโยง


whenCellEmpty()

ตั้งค่ากฎการจัดรูปแบบตามเงื่อนไขให้ทริกเกอร์เมื่อเซลล์ว่าง

// Adds a conditional format rule to a sheet that causes cells in range A1:B3 to // turn red if they are empty. const sheet = SpreadsheetApp.getActiveSheet(); const range = sheet.getRange('A1:B3'); const rule = SpreadsheetApp.newConditionalFormatRule()                  .whenCellEmpty()                  .setBackground('#FF0000')                  .setRanges([range])                  .build(); const rules = sheet.getConditionalFormatRules(); rules.push(rule); sheet.setConditionalFormatRules(rules);

รีเทิร์น

ConditionalFormatRuleBuilder — ตัวสร้างสำหรับการเชื่อมโยง


whenCellNotEmpty()

ตั้งค่ากฎการจัดรูปแบบตามเงื่อนไขให้ทริกเกอร์เมื่อเซลล์ไม่ว่าง

// Adds a conditional format rule to a sheet that causes cells in range A1:B3 to // turn red if they are not empty. const sheet = SpreadsheetApp.getActiveSheet(); const range = sheet.getRange('A1:B3'); const rule = SpreadsheetApp.newConditionalFormatRule()                  .whenCellNotEmpty()                  .setBackground('#FF0000')                  .setRanges([range])                  .build(); const rules = sheet.getConditionalFormatRules(); rules.push(rule); sheet.setConditionalFormatRules(rules);

รีเทิร์น

ConditionalFormatRuleBuilder — ตัวสร้างสำหรับการเชื่อมโยง


whenDateAfter(date)

ตั้งค่ากฎการจัดรูปแบบตามเงื่อนไขให้ทริกเกอร์เมื่อวันที่อยู่หลังค่าที่ระบุ

// Adds a conditional format rule to a sheet that causes cells in range A1:B3 to // turn red if they contain a date after 11/4/1993.  const sheet = SpreadsheetApp.getActiveSheet(); const range = sheet.getRange('A1:B3'); const rule = SpreadsheetApp.newConditionalFormatRule()                  .whenDateAfter(new Date('11/4/1993'))                  .setBackground('#FF0000')                  .setRanges([range])                  .build(); const rules = sheet.getConditionalFormatRules(); rules.push(rule); sheet.setConditionalFormatRules(rules);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
dateDateวันที่ล่าสุด

รีเทิร์น

ConditionalFormatRuleBuilder — ตัวสร้างสำหรับการเชื่อมโยง


whenDateAfter(date)

ตั้งค่ากฎการจัดรูปแบบตามเงื่อนไขให้ทริกเกอร์เมื่อวันที่อยู่หลังวันที่สัมพัทธ์ที่ระบุ

// Adds a conditional format rule to a sheet that causes cells in range A1:B3 to // turn red if they contain a date after today.  const sheet = SpreadsheetApp.getActiveSheet(); const range = sheet.getRange('A1:B3'); const rule = SpreadsheetApp.newConditionalFormatRule()                  .whenDateAfter(SpreadsheetApp.RelativeDate.TODAY)                  .setBackground('#FF0000')                  .setRanges([range])                  .build(); const rules = sheet.getConditionalFormatRules(); rules.push(rule); sheet.setConditionalFormatRules(rules);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
dateRelativeDateวันที่ล่าสุดที่เกี่ยวข้องกับประเภทวันที่ที่เลือก

รีเทิร์น

ConditionalFormatRuleBuilder — ตัวสร้างสำหรับการเชื่อมโยง


whenDateBefore(date)

ตั้งค่ากฎการจัดรูปแบบตามเงื่อนไขให้ทริกเกอร์เมื่อวันที่อยู่ก่อนวันที่ที่ระบุ

// Adds a conditional format rule to a sheet that causes cells in range A1:B3 to // turn red if they contain a date before 11/4/1993.  const sheet = SpreadsheetApp.getActiveSheet(); const range = sheet.getRange('A1:B3'); const rule = SpreadsheetApp.newConditionalFormatRule()                  .whenDateBefore(new Date('11/4/1993'))                  .setBackground('#FF0000')                  .setRanges([range])                  .build(); const rules = sheet.getConditionalFormatRules(); rules.push(rule); sheet.setConditionalFormatRules(rules);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
dateDateวันที่เร็วที่สุดที่ยอมรับไม่ได้

รีเทิร์น

ConditionalFormatRuleBuilder — ตัวสร้างสำหรับการเชื่อมโยง


whenDateBefore(date)

ตั้งค่ากฎการจัดรูปแบบตามเงื่อนไขให้ทริกเกอร์เมื่อวันที่อยู่ก่อนวันที่สัมพัทธ์ที่ระบุ

// Adds a conditional format rule to a sheet that causes cells in range A1:B3 to // turn red if they contain a date before today.  const sheet = SpreadsheetApp.getActiveSheet(); const range = sheet.getRange('A1:B3'); const rule = SpreadsheetApp.newConditionalFormatRule()                  .whenDateBefore(SpreadsheetApp.RelativeDate.TODAY)                  .setBackground('#FF0000')                  .setRanges([range])                  .build(); const rules = sheet.getConditionalFormatRules(); rules.push(rule); sheet.setConditionalFormatRules(rules);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
dateRelativeDateวันที่ล่าสุดที่เกี่ยวข้องกับประเภทวันที่ที่เลือก

รีเทิร์น

ConditionalFormatRuleBuilder — ตัวสร้างสำหรับการเชื่อมโยง


whenDateEqualTo(date)

ตั้งค่ากฎการจัดรูปแบบตามเงื่อนไขให้ทริกเกอร์เมื่อวันที่เท่ากับวันที่ที่ระบุ

// Adds a conditional format rule to a sheet that causes cells in range A1:B3 to // turn red if they contain the date 11/4/1993.  const sheet = SpreadsheetApp.getActiveSheet(); const range = sheet.getRange('A1:B3'); const rule = SpreadsheetApp.newConditionalFormatRule()                  .whenDateEqualTo(new Date('11/4/1993'))                  .setBackground('#FF0000')                  .setRanges([range])                  .build(); const rules = sheet.getConditionalFormatRules(); rules.push(rule); sheet.setConditionalFormatRules(rules);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
dateDateวันที่ที่ยอมรับได้เพียงวันเดียว

รีเทิร์น

ConditionalFormatRuleBuilder — ตัวสร้างสำหรับการเชื่อมโยง


whenDateEqualTo(date)

ตั้งค่ากฎการจัดรูปแบบตามเงื่อนไขให้ทริกเกอร์เมื่อวันที่เท่ากับวันที่สัมพัทธ์ที่ระบุ

// Adds a conditional format rule to a sheet that causes cells in range A1:B3 to // turn red if they contain todays date.  const sheet = SpreadsheetApp.getActiveSheet(); const range = sheet.getRange('A1:B3'); const rule = SpreadsheetApp.newConditionalFormatRule()                  .whenDateEqualTo(SpreadsheetApp.RelativeDate.TODAY)                  .setBackground('#FF0000')                  .setRanges([range])                  .build(); const rules = sheet.getConditionalFormatRules(); rules.push(rule); sheet.setConditionalFormatRules(rules);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
dateRelativeDateวันที่ล่าสุดที่เกี่ยวข้องกับประเภทวันที่ที่เลือก

รีเทิร์น

ConditionalFormatRuleBuilder — ตัวสร้างสำหรับการเชื่อมโยง


whenFormulaSatisfied(formula)

กำหนดกฎการจัดรูปแบบตามเงื่อนไขให้ทริกเกอร์เมื่อสูตรที่ระบุให้ค่าเป็น true

// Adds a conditional format rule to a sheet that causes cells in range A1:B3 to // turn red if they satisfy the condition "=EQ(B4, C3)".  const sheet = SpreadsheetApp.getActiveSheet(); const range = sheet.getRange('A1:B3'); const rule = SpreadsheetApp.newConditionalFormatRule()                  .whenFormulaSatisfied('=EQ(B4, C3)')                  .setBackground('#FF0000')                  .setRanges([range])                  .build(); const rules = sheet.getConditionalFormatRules(); rules.push(rule); sheet.setConditionalFormatRules(rules);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
formulaStringสูตรที่กำหนดเองซึ่งประเมินเป็น true หากอินพุตถูกต้อง

รีเทิร์น

ConditionalFormatRuleBuilder — ตัวสร้างสำหรับการเชื่อมโยง


whenNumberBetween(start, end)

ตั้งค่ากฎการจัดรูปแบบตามเงื่อนไขให้ทริกเกอร์เมื่อตัวเลขอยู่ระหว่างหรือเป็นค่าใดค่าหนึ่งของค่าที่ระบุ 2 ค่า

// Adds a conditional format rule to a sheet that causes cells in range A1:B3 to // turn red if they contain a number between 1 and 10.  const sheet = SpreadsheetApp.getActiveSheet(); const range = sheet.getRange('A1:B3'); const rule = SpreadsheetApp.newConditionalFormatRule()                  .whenNumberBetween(1, 10)                  .setBackground('#FF0000')                  .setRanges([range])                  .build(); const rules = sheet.getConditionalFormatRules(); rules.push(rule); sheet.setConditionalFormatRules(rules);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
startNumberค่าต่ำสุดที่ยอมรับได้
endNumberค่าสูงสุดที่ยอมรับได้

รีเทิร์น

ConditionalFormatRuleBuilder — ตัวสร้างสำหรับการเชื่อมโยง


whenNumberEqualTo(number)

ตั้งค่ากฎการจัดรูปแบบตามเงื่อนไขให้ทริกเกอร์เมื่อตัวเลขเท่ากับค่าที่ระบุ

// Adds a conditional format rule to a sheet that causes cells in range A1:B3 to // turn red if they contain the number 10.  const sheet = SpreadsheetApp.getActiveSheet(); const range = sheet.getRange('A1:B3'); const rule = SpreadsheetApp.newConditionalFormatRule()                  .whenNumberEqualTo(10)                  .setBackground('#FF0000')                  .setRanges([range])                  .build(); const rules = sheet.getConditionalFormatRules(); rules.push(rule); sheet.setConditionalFormatRules(rules);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
numberNumberค่าที่ยอมรับเพียงค่าเดียว

รีเทิร์น

ConditionalFormatRuleBuilder — ตัวสร้างสำหรับการเชื่อมโยง


whenNumberGreaterThan(number)

กำหนดกฎการจัดรูปแบบตามเงื่อนไขให้ทริกเกอร์เมื่อตัวเลขมากกว่าค่าที่ระบุ

// Adds a conditional format rule to a sheet that causes cells in range A1:B3 to // turn red if they contain a number greater than 10.  const sheet = SpreadsheetApp.getActiveSheet(); const range = sheet.getRange('A1:B3'); const rule = SpreadsheetApp.newConditionalFormatRule()                  .whenNumberGreaterThan(10)                  .setBackground('#FF0000')                  .setRanges([range])                  .build(); const rules = sheet.getConditionalFormatRules(); rules.push(rule); sheet.setConditionalFormatRules(rules);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
numberNumberค่าสูงสุดที่ยอมรับไม่ได้

รีเทิร์น

ConditionalFormatRuleBuilder — ตัวสร้างสำหรับการเชื่อมโยง


whenNumberGreaterThanOrEqualTo(number)

ตั้งค่ากฎการจัดรูปแบบตามเงื่อนไขให้ทริกเกอร์เมื่อตัวเลขมากกว่าหรือเท่ากับค่าที่ระบุ

// Adds a conditional format rule to a sheet that causes cells in range A1:B3 to // turn red if they contain a number greater than or equal to 10.  const sheet = SpreadsheetApp.getActiveSheet(); const range = sheet.getRange('A1:B3'); const rule = SpreadsheetApp.newConditionalFormatRule()                  .whenNumberGreaterThanOrEqualTo(10)                  .setBackground('#FF0000')                  .setRanges([range])                  .build(); const rules = sheet.getConditionalFormatRules(); rules.push(rule); sheet.setConditionalFormatRules(rules);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
numberNumberค่าต่ำสุดที่ยอมรับได้

รีเทิร์น

ConditionalFormatRuleBuilder — ตัวสร้างสำหรับการเชื่อมโยง


whenNumberLessThan(number)

ตั้งค่ากฎการจัดรูปแบบตามเงื่อนไขให้ทริกเกอร์เมื่อตัวเลขน้อยกว่าค่าที่ระบุ

// Adds a conditional format rule to a sheet that causes cells in range A1:B3 to // turn red if they contain a number less than 10.  const sheet = SpreadsheetApp.getActiveSheet(); const range = sheet.getRange('A1:B3'); const rule = SpreadsheetApp.newConditionalFormatRule()                  .whenNumberLessThan(10)                  .setBackground('#FF0000')                  .setRanges([range])                  .build(); const rules = sheet.getConditionalFormatRules(); rules.push(rule); sheet.setConditionalFormatRules(rules);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
numberNumberค่าต่ำสุดที่ยอมรับไม่ได้

รีเทิร์น

ConditionalFormatRuleBuilder — ตัวสร้างสำหรับการเชื่อมโยง


whenNumberLessThanOrEqualTo(number)

ตั้งค่ากฎการจัดรูปแบบตามเงื่อนไขให้ทริกเกอร์เมื่อตัวเลขน้อยกว่าหรือเท่ากับค่าที่ระบุ

// Adds a conditional format rule to a sheet that causes cells in range A1:B3 to // turn red if they contain a number less than or equal to 10.  const sheet = SpreadsheetApp.getActiveSheet(); const range = sheet.getRange('A1:B3'); const rule = SpreadsheetApp.newConditionalFormatRule()                  .whenNumberLessThanOrEqualTo(10)                  .setBackground('#FF0000')                  .setRanges([range])                  .build(); const rules = sheet.getConditionalFormatRules(); rules.push(rule); sheet.setConditionalFormatRules(rules);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
numberNumberค่าสูงสุดที่ยอมรับได้

รีเทิร์น

ConditionalFormatRuleBuilder — ตัวสร้างสำหรับการเชื่อมโยง


whenNumberNotBetween(start, end)

ตั้งค่ากฎการจัดรูปแบบตามเงื่อนไขให้ทริกเกอร์เมื่อตัวเลขไม่ได้อยู่ระหว่างค่าที่ระบุ 2 ค่า และไม่ใช่ค่าใดค่าหนึ่ง

// Adds a conditional format rule to a sheet that causes cells in range A1:B3 to // turn red if they contain a number not between 1 and 10.  const sheet = SpreadsheetApp.getActiveSheet(); const range = sheet.getRange('A1:B3'); const rule = SpreadsheetApp.newConditionalFormatRule()                  .whenNumberNotBetween(1, 10)                  .setBackground('#FF0000')                  .setRanges([range])                  .build(); const rules = sheet.getConditionalFormatRules(); rules.push(rule); sheet.setConditionalFormatRules(rules);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
startNumberค่าต่ำสุดที่ยอมรับไม่ได้
endNumberค่าสูงสุดที่ยอมรับไม่ได้

รีเทิร์น

ConditionalFormatRuleBuilder — ตัวสร้างสำหรับการเชื่อมโยง


whenNumberNotEqualTo(number)

กำหนดกฎการจัดรูปแบบตามเงื่อนไขให้ทริกเกอร์เมื่อตัวเลขไม่เท่ากับค่าที่ระบุ

// Adds a conditional format rule to a sheet that causes cells in range A1:B3 to // turn red if they don't contain the number 10.  const sheet = SpreadsheetApp.getActiveSheet(); const range = sheet.getRange('A1:B3'); const rule = SpreadsheetApp.newConditionalFormatRule()                  .whenNumberNotEqualTo(10)                  .setBackground('#FF0000')                  .setRanges([range])                  .build(); const rules = sheet.getConditionalFormatRules(); rules.push(rule); sheet.setConditionalFormatRules(rules);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
numberNumberค่าเดียวที่ยอมรับไม่ได้

รีเทิร์น

ConditionalFormatRuleBuilder — ตัวสร้างสำหรับการเชื่อมโยง


whenTextContains(text)

ตั้งค่ากฎการจัดรูปแบบตามเงื่อนไขให้ทริกเกอร์เมื่ออินพุตมีค่าที่ระบุ

// Adds a conditional format rule to a sheet that causes cells in range A1:B3 to // turn red if they contain the text "hello".  const sheet = SpreadsheetApp.getActiveSheet(); const range = sheet.getRange('A1:B3'); const rule = SpreadsheetApp.newConditionalFormatRule()                  .whenTextContains('hello')                  .setBackground('#FF0000')                  .setRanges([range])                  .build(); const rules = sheet.getConditionalFormatRules(); rules.push(rule); sheet.setConditionalFormatRules(rules);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
textStringค่าที่อินพุตต้องมี

รีเทิร์น

ConditionalFormatRuleBuilder — ตัวสร้างสำหรับการเชื่อมโยง


whenTextDoesNotContain(text)

ตั้งค่ากฎการจัดรูปแบบตามเงื่อนไขให้ทริกเกอร์เมื่ออินพุตไม่มีค่าที่ระบุ

// Adds a conditional format rule to a sheet that causes cells in range A1:B3 to // turn red if they don't contain the text "hello".  const sheet = SpreadsheetApp.getActiveSheet(); const range = sheet.getRange('A1:B3'); const rule = SpreadsheetApp.newConditionalFormatRule()                  .whenTextDoesNotContain('hello')                  .setBackground('#FF0000')                  .setRanges([range])                  .build(); const rules = sheet.getConditionalFormatRules(); rules.push(rule); sheet.setConditionalFormatRules(rules);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
textStringค่าที่อินพุตต้องไม่มี

รีเทิร์น

ConditionalFormatRuleBuilder — ตัวสร้างสำหรับการเชื่อมโยง


whenTextEndsWith(text)

ตั้งค่ากฎการจัดรูปแบบตามเงื่อนไขให้ทริกเกอร์เมื่ออินพุตลงท้ายด้วยค่าที่ระบุ

// Adds a conditional format rule to a sheet that causes cells in range A1:B3 to // turn red if they end with the text "hello".  const sheet = SpreadsheetApp.getActiveSheet(); const range = sheet.getRange('A1:B3'); const rule = SpreadsheetApp.newConditionalFormatRule()                  .whenTextEndsWith('hello')                  .setBackground('#FF0000')                  .setRanges([range])                  .build(); const rules = sheet.getConditionalFormatRules(); rules.push(rule); sheet.setConditionalFormatRules(rules);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
textStringข้อความที่จะเปรียบเทียบกับส่วนท้ายของสตริง

รีเทิร์น

ConditionalFormatRuleBuilder — ตัวสร้างสำหรับการเชื่อมโยง


whenTextEqualTo(text)

ตั้งค่ากฎการจัดรูปแบบตามเงื่อนไขให้ทริกเกอร์เมื่ออินพุตเท่ากับค่าที่ระบุ

// Adds a conditional format rule to a sheet that causes cells in range A1:B3 to // turn red if they have text equal to "hello".  const sheet = SpreadsheetApp.getActiveSheet(); const range = sheet.getRange('A1:B3'); const rule = SpreadsheetApp.newConditionalFormatRule()                  .whenTextEqualTo('hello')                  .setBackground('#FF0000')                  .setRanges([range])                  .build(); const rules = sheet.getConditionalFormatRules(); rules.push(rule); sheet.setConditionalFormatRules(rules);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
textStringค่าที่ยอมรับเพียงค่าเดียว

รีเทิร์น

ConditionalFormatRuleBuilder — ตัวสร้างสำหรับการเชื่อมโยง


whenTextStartsWith(text)

ตั้งค่ากฎการจัดรูปแบบตามเงื่อนไขให้ทริกเกอร์เมื่ออินพุตเริ่มต้นด้วยค่าที่ระบุ

// Adds a conditional format rule to a sheet that causes cells in range A1:B3 to // turn red if they start with the text "hello".  const sheet = SpreadsheetApp.getActiveSheet(); const range = sheet.getRange('A1:B3'); const rule = SpreadsheetApp.newConditionalFormatRule()                  .whenTextStartsWith('hello')                  .setBackground('#FF0000')                  .setRanges([range])                  .build(); const rules = sheet.getConditionalFormatRules(); rules.push(rule); sheet.setConditionalFormatRules(rules);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
textStringข้อความที่จะเปรียบเทียบกับจุดเริ่มต้นของสตริง

รีเทิร์น

ConditionalFormatRuleBuilder — ตัวสร้างสำหรับการเชื่อมโยง


withCriteria(criteria, args)

ตั้งค่ากฎการจัดรูปแบบตามเงื่อนไขเป็นเกณฑ์ที่กำหนดโดยค่า BooleanCriteria ซึ่งโดยปกติจะมาจาก criteria และ arguments ของกฎที่มีอยู่

// Adds a new conditional format rule that is a copy of the first active // conditional format rule, except it instead sets its cells to have a black // background color.  const sheet = SpreadsheetApp.getActiveSheet(); const rules = sheet.getConditionalFormatRules(); const booleanCondition = rules[0].getBooleanCondition(); if (booleanCondition != null) {   const rule = SpreadsheetApp.newConditionalFormatRule()                    .withCriteria(                        booleanCondition.getCriteriaType(),                        booleanCondition.getCriteriaValues(),                        )                    .setBackground('#000000')                    .setRanges(rules[0].getRanges())                    .build();   rules.push(rule); } sheet.setConditionalFormatRules(rules);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
criteriaBooleanCriteriaประเภทของเกณฑ์การจัดรูปแบบตามเงื่อนไข
argsObject[]อาร์กิวเมนต์อาร์เรย์ที่เหมาะสมกับประเภทเกณฑ์ จำนวนอาร์กิวเมนต์และ ประเภทของอาร์กิวเมนต์ตรงกับwhen...()เมธอดที่เกี่ยวข้องด้านบน

รีเทิร์น

ConditionalFormatRuleBuilder — ตัวสร้างสำหรับการเชื่อมโยง