เครื่องมือสร้างกฎการจัดรูปแบบตามเงื่อนไข
// 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. var sheet = SpreadsheetApp.getActiveSheet(); var range = sheet.getRange("A1:B3"); var rule = SpreadsheetApp.newConditionalFormatRule() .whenNumberBetween(1, 10) .setBackground("#FF0000") .setRanges([range]) .build(); var 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 | ตั้งค่าช่องการไล่ระดับสี Maxpoint ของกฎการจัดรูปแบบตามเงื่อนไข |
setGradientMaxpointWithValue(color, type, value) | ConditionalFormatRuleBuilder | ตั้งค่าช่องการไล่ระดับสี Maxpoint ของกฎการจัดรูปแบบตามเงื่อนไข |
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. 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[]
— ช่วงที่จะใช้กฎการจัดรูปแบบตามเงื่อนไขนี้
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". var sheet = SpreadsheetApp.getActiveSheet(); var range = sheet.getRange("A1:B3"); var rule = SpreadsheetApp.newConditionalFormatRule() .whenTextEqualTo("hello") .setBackground("#FF0000") .setRanges([range]) .build(); var rules = sheet.getConditionalFormatRules(); rules.push(rule); sheet.setConditionalFormatRules(rules);
พารามิเตอร์
ชื่อ | Type | คำอธิบาย |
---|---|---|
color | String | สีที่ต้องการหรือ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". var sheet = SpreadsheetApp.getActiveSheet(); var range = sheet.getRange("A1:B3"); var color = SpreadsheetApp.newColor() .setThemeColor(SpreadsheetApp.ThemeColorType.BACKGROUND) .build(); var rule = SpreadsheetApp.newConditionalFormatRule() .whenTextEqualTo("hello") .setBackground(color) .setRanges([range]) .build(); var rules = sheet.getConditionalFormatRules(); rules.push(rule); sheet.setConditionalFormatRules(rules);
พารามิเตอร์
ชื่อ | Type | คำอธิบาย |
---|---|---|
color | Color | วัตถุสีที่ต้องการหรือ 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". var sheet = SpreadsheetApp.getActiveSheet(); var range = sheet.getRange("A1:B3"); var rule = SpreadsheetApp.newConditionalFormatRule() .whenTextEqualTo("hello") .setBold(true) .setRanges([range]) .build(); var rules = sheet.getConditionalFormatRules(); rules.push(rule); sheet.setConditionalFormatRules(rules);
พารามิเตอร์
ชื่อ | Type | คำอธิบาย |
---|---|---|
bold | Boolean | ระบุว่าข้อความควรเป็นตัวหนาหรือไม่หากเป็นไปตามเงื่อนไขรูปแบบ 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". var sheet = SpreadsheetApp.getActiveSheet(); var range = sheet.getRange("A1:B3"); var rule = SpreadsheetApp.newConditionalFormatRule() .whenTextEqualTo("hello") .setFontColor("#FF0000") .setRanges([range]) .build(); var rules = sheet.getConditionalFormatRules(); rules.push(rule); sheet.setConditionalFormatRules(rules);
พารามิเตอร์
ชื่อ | Type | คำอธิบาย |
---|---|---|
color | String | สีที่ต้องการหรือ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". var sheet = SpreadsheetApp.getActiveSheet(); var range = sheet.getRange("A1:B3"); var color = SpreadsheetApp.newColor() .setThemeColor(SpreadsheetApp.ThemeColorType.TEXT) .build(); var rule = SpreadsheetApp.newConditionalFormatRule() .whenTextEqualTo("hello") .setFontColor(color) .setRanges([range]) .build(); var rules = sheet.getConditionalFormatRules(); rules.push(rule); sheet.setConditionalFormatRules(rules);
พารามิเตอร์
ชื่อ | Type | คำอธิบาย |
---|---|---|
color | Color | วัตถุสีที่ต้องการหรือ 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. var sheet = SpreadsheetApp.getActiveSheet(); var range = sheet.getRange("A1:B3"); var rule = SpreadsheetApp.newConditionalFormatRule() .setGradientMaxpoint("#FF0000") .setGradientMinpoint("#FFFFFF") .setRanges([range]) .build(); var rules = sheet.getConditionalFormatRules(); rules.push(rule); sheet.setConditionalFormatRules(rules);
พารามิเตอร์
ชื่อ | Type | คำอธิบาย |
---|---|---|
color | String | สีระดับสูงสุดที่จะตั้งค่า |
รีเทิร์น
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. var sheet = SpreadsheetApp.getActiveSheet(); var range = sheet.getRange("A1:B3"); var textColor = SpreadsheetApp.newColor() .setThemeColor(SpreadsheetApp.ThemeColorType.TEXT) .build(); var backgroundColor = SpreadsheetApp.newColor() .setThemeColor(SpreadsheetApp.ThemeColorType.BACKGROUND) .build(); var rule = SpreadsheetApp.newConditionalFormatRule() .setGradientMaxpoint(textColor) .setGradientMinpoint(backgroundColor) .setRanges([range]) .build(); var rules = sheet.getConditionalFormatRules(); rules.push(rule); sheet.setConditionalFormatRules(rules);
พารามิเตอร์
ชื่อ | Type | คำอธิบาย |
---|---|---|
color | Color | วัตถุสีระดับสูงสุดที่จะตั้งค่า |
รีเทิร์น
ConditionalFormatRuleBuilder
— เครื่องมือสร้างสำหรับเชน
setGradientMaxpointObjectWithValue(color, type, value)
ตั้งค่าช่องการไล่ระดับสี Maxpoint ของกฎการจัดรูปแบบตามเงื่อนไข
// 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. var sheet = SpreadsheetApp.getActiveSheet(); var range = sheet.getRange("A1:B3"); var color1 = SpreadsheetApp.newColor() .setThemeColor(SpreadsheetApp.ThemeColorType.ACCENT1) .build(); var color2 = SpreadsheetApp.newColor() .setThemeColor(SpreadsheetApp.ThemeColorType.ACCENT2) .build(); var color3 = SpreadsheetApp.newColor() .setThemeColor(SpreadsheetApp.ThemeColorType.ACCENT3) .build(); var rule = SpreadsheetApp.newConditionalFormatRule() .setGradientMaxpointWithValue(color1, SpreadsheetApp.InterpolationType.NUMBER, "100") .setGradientMidpointWithValue(color2, SpreadsheetApp.InterpolationType.NUMBER, "50") .setGradientMinpointWithValue(color3, SpreadsheetApp.InterpolationType.NUMBER, "0") .setRanges([range]) .build(); var rules = sheet.getConditionalFormatRules(); rules.push(rule); sheet.setConditionalFormatRules(rules);
พารามิเตอร์
ชื่อ | Type | คำอธิบาย |
---|---|---|
color | Color | สีระดับสูงสุดที่จะตั้งค่า |
type | InterpolationType | ประเภทการประมาณค่าในช่วงสูงสุดที่ตั้งค่า |
value | String | ค่าสูงสุดที่จะตั้ง |
รีเทิร์น
ConditionalFormatRuleBuilder
— เครื่องมือสร้างสำหรับเชน
setGradientMaxpointWithValue(color, type, value)
ตั้งค่าช่องการไล่ระดับสี Maxpoint ของกฎการจัดรูปแบบตามเงื่อนไข
// 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. var sheet = SpreadsheetApp.getActiveSheet(); var range = sheet.getRange("A1:B3"); var rule = SpreadsheetApp.newConditionalFormatRule() .setGradientMaxpointWithValue("#0000FF", SpreadsheetApp.InterpolationType.NUMBER, "100") .setGradientMidpointWithValue("#00FF00", SpreadsheetApp.InterpolationType.NUMBER, "50") .setGradientMinpointWithValue("#FF0000", SpreadsheetApp.InterpolationType.NUMBER, "0") .setRanges([range]) .build(); var rules = sheet.getConditionalFormatRules(); rules.push(rule); sheet.setConditionalFormatRules(rules);
พารามิเตอร์
ชื่อ | Type | คำอธิบาย |
---|---|---|
color | String | สีระดับสูงสุดที่จะตั้งค่า |
type | InterpolationType | ประเภทการประมาณค่าในช่วงสูงสุดที่ตั้งค่า |
value | String | ค่าสูงสุดที่จะตั้ง |
รีเทิร์น
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. var sheet = SpreadsheetApp.getActiveSheet(); var range = sheet.getRange("A1:B3"); var color1 = SpreadsheetApp.newColor() .setThemeColor(SpreadsheetApp.ThemeColorType.ACCENT1) .build(); var color2 = SpreadsheetApp.newColor() .setThemeColor(SpreadsheetApp.ThemeColorType.ACCENT2) .build(); var color3 = SpreadsheetApp.newColor() .setThemeColor(SpreadsheetApp.ThemeColorType.ACCENT3) .build(); var rule = SpreadsheetApp.newConditionalFormatRule() .setGradientMaxpointWithValue(color1, SpreadsheetApp.InterpolationType.NUMBER, "100") .setGradientMidpointWithValue(color2, SpreadsheetApp.InterpolationType.NUMBER, "50") .setGradientMinpointWithValue(color3, SpreadsheetApp.InterpolationType.NUMBER, "0") .setRanges([range]) .build(); var rules = sheet.getConditionalFormatRules(); rules.push(rule); sheet.setConditionalFormatRules(rules);
พารามิเตอร์
ชื่อ | Type | คำอธิบาย |
---|---|---|
color | Color | สีที่จุดกึ่งกลางที่จะตั้งค่า |
type | InterpolationType | ประเภทการประมาณค่าในช่วงจุดกึ่งกลางที่จะตั้งค่า หรือ null เพื่อล้าง |
value | String | ค่ากึ่งกลางที่จะตั้ง |
รีเทิร์น
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. var sheet = SpreadsheetApp.getActiveSheet(); var range = sheet.getRange("A1:B3"); var rule = SpreadsheetApp.newConditionalFormatRule() .setGradientMaxpointWithValue("#0000FF", SpreadsheetApp.InterpolationType.NUMBER, "100") .setGradientMidpointWithValue("#00FF00", SpreadsheetApp.InterpolationType.NUMBER, "50") .setGradientMinpointWithValue("#FF0000", SpreadsheetApp.InterpolationType.NUMBER, "0") .setRanges([range]) .build(); var rules = sheet.getConditionalFormatRules(); rules.push(rule); sheet.setConditionalFormatRules(rules);
พารามิเตอร์
ชื่อ | Type | คำอธิบาย |
---|---|---|
color | String | สีที่จุดกึ่งกลางที่จะตั้งค่า |
type | InterpolationType | ประเภทการประมาณค่าในช่วงจุดกึ่งกลางที่จะตั้งค่า หรือ null เพื่อล้าง |
value | String | ค่ากึ่งกลางที่จะตั้ง |
รีเทิร์น
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. var sheet = SpreadsheetApp.getActiveSheet(); var range = sheet.getRange("A1:B3"); var rule = SpreadsheetApp.newConditionalFormatRule() .setGradientMaxpoint("#FF0000") .setGradientMinpoint("#FFFFFF") .setRanges([range]) .build(); var rules = sheet.getConditionalFormatRules(); rules.push(rule); sheet.setConditionalFormatRules(rules);
พารามิเตอร์
ชื่อ | Type | คำอธิบาย |
---|---|---|
color | String | สีของจุดต่ำสุดที่จะตั้งค่า |
รีเทิร์น
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. var sheet = SpreadsheetApp.getActiveSheet(); var range = sheet.getRange("A1:B3"); var textColor = SpreadsheetApp.newColor() .setThemeColor(SpreadsheetApp.ThemeColorType.TEXT) .build(); var backgroundColor = SpreadsheetApp.newColor() .setThemeColor(SpreadsheetApp.ThemeColorType.BACKGROUND) .build(); var rule = SpreadsheetApp.newConditionalFormatRule() .setGradientMaxpoint(textColor) .setGradientMinpoint(backgroundColor) .setRanges([range]) .build(); var rules = sheet.getConditionalFormatRules(); rules.push(rule); sheet.setConditionalFormatRules(rules);
พารามิเตอร์
ชื่อ | Type | คำอธิบาย |
---|---|---|
color | Color | วัตถุสีแบบจุดต่ำสุดที่จะตั้งค่า |
รีเทิร์น
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. var sheet = SpreadsheetApp.getActiveSheet(); var range = sheet.getRange("A1:B3"); var color1 = SpreadsheetApp.newColor() .setThemeColor(SpreadsheetApp.ThemeColorType.ACCENT1) .build(); var color2 = SpreadsheetApp.newColor() .setThemeColor(SpreadsheetApp.ThemeColorType.ACCENT2) .build(); var color3 = SpreadsheetApp.newColor() .setThemeColor(SpreadsheetApp.ThemeColorType.ACCENT3) .build(); var rule = SpreadsheetApp.newConditionalFormatRule() .setGradientMaxpointWithValue(color1, SpreadsheetApp.InterpolationType.NUMBER, "100") .setGradientMidpointWithValue(color2, SpreadsheetApp.InterpolationType.NUMBER, "50") .setGradientMinpointWithValue(color3, SpreadsheetApp.InterpolationType.NUMBER, "0") .setRanges([range]) .build(); var rules = sheet.getConditionalFormatRules(); rules.push(rule); sheet.setConditionalFormatRules(rules);
พารามิเตอร์
ชื่อ | Type | คำอธิบาย |
---|---|---|
color | Color | สีของจุดต่ำสุดที่จะตั้งค่า |
type | InterpolationType | ประเภทการประมาณค่าต่ำสุดที่จะตั้งค่า |
value | String | ค่าต่ำสุดที่จะตั้ง |
รีเทิร์น
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. var sheet = SpreadsheetApp.getActiveSheet(); var range = sheet.getRange("A1:B3"); var rule = SpreadsheetApp.newConditionalFormatRule() .setGradientMaxpointWithValue("#0000FF", SpreadsheetApp.InterpolationType.NUMBER, "100") .setGradientMidpointWithValue("#00FF00", SpreadsheetApp.InterpolationType.NUMBER, "50") .setGradientMinpointWithValue("#FF0000", SpreadsheetApp.InterpolationType.NUMBER, "0") .setRanges([range]) .build(); var rules = sheet.getConditionalFormatRules(); rules.push(rule); sheet.setConditionalFormatRules(rules);
พารามิเตอร์
ชื่อ | Type | คำอธิบาย |
---|---|---|
color | String | สีของจุดต่ำสุดที่จะตั้งค่า |
type | InterpolationType | ประเภทการประมาณค่าต่ำสุดที่จะตั้งค่า |
value | String | ค่าต่ำสุดที่จะตั้ง |
รีเทิร์น
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". var sheet = SpreadsheetApp.getActiveSheet(); var range = sheet.getRange("A1:B3"); var rule = SpreadsheetApp.newConditionalFormatRule() .whenTextEqualTo("hello") .setItalic(true) .setRanges([range]) .build(); var rules = sheet.getConditionalFormatRules(); rules.push(rule); sheet.setConditionalFormatRules(rules);
พารามิเตอร์
ชื่อ | Type | คำอธิบาย |
---|---|---|
italic | Boolean | ระบุว่าข้อความควรเป็นตัวเอียงหรือไม่หากตรงตามเงื่อนไขของรูปแบบ 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. var sheet = SpreadsheetApp.getActiveSheet(); var rangeOne = sheet.getRange("A1:B3"); var rangeTwo = sheet.getRange("D4:F6"); var rule = SpreadsheetApp.newConditionalFormatRule() .whenNumberBetween(1, 10) .setBackground("#FF0000") .setRanges([rangeOne, rangeTwo]) .build(); var rules = sheet.getConditionalFormatRules(); rules.push(rule); sheet.setConditionalFormatRules(rules);
พารามิเตอร์
ชื่อ | Type | คำอธิบาย |
---|---|---|
ranges | Range[] | ช่วงที่จะใช้กฎการจัดรูปแบบตามเงื่อนไขนี้ |
รีเทิร์น
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". var sheet = SpreadsheetApp.getActiveSheet(); var range = sheet.getRange("A1:B3"); var rule = SpreadsheetApp.newConditionalFormatRule() .whenTextEqualTo("hello") .setStrikethrough(true) .setRanges([range]) .build(); var rules = sheet.getConditionalFormatRules(); rules.push(rule); sheet.setConditionalFormatRules(rules);
พารามิเตอร์
ชื่อ | Type | คำอธิบาย |
---|---|---|
strikethrough | Boolean | กำหนดว่าข้อความควรขีดทับหรือไม่หากเป็นไปตามเงื่อนไขรูปแบบ 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". var sheet = SpreadsheetApp.getActiveSheet(); var range = sheet.getRange("A1:B3"); var rule = SpreadsheetApp.newConditionalFormatRule() .whenTextEqualTo("hello") .setUnderline(true) .setRanges([range]) .build(); var rules = sheet.getConditionalFormatRules(); rules.push(rule); sheet.setConditionalFormatRules(rules);
พารามิเตอร์
ชื่อ | Type | คำอธิบาย |
---|---|---|
underline | Boolean | กำหนดว่าควรขีดเส้นใต้ข้อความหรือไม่หากเป็นไปตามเงื่อนไขรูปแบบ 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. var sheet = SpreadsheetApp.getActiveSheet(); var range = sheet.getRange("A1:B3"); var rule = SpreadsheetApp.newConditionalFormatRule() .whenCellEmpty() .setBackground("#FF0000") .setRanges([range]) .build(); var 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. var sheet = SpreadsheetApp.getActiveSheet(); var range = sheet.getRange("A1:B3"); var rule = SpreadsheetApp.newConditionalFormatRule() .whenCellNotEmpty() .setBackground("#FF0000") .setRanges([range]) .build(); var 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. var sheet = SpreadsheetApp.getActiveSheet(); var range = sheet.getRange("A1:B3"); var rule = SpreadsheetApp.newConditionalFormatRule() .whenDateAfter(new Date("11/4/1993")) .setBackground("#FF0000") .setRanges([range]) .build(); var rules = sheet.getConditionalFormatRules(); rules.push(rule); sheet.setConditionalFormatRules(rules);
พารามิเตอร์
ชื่อ | Type | คำอธิบาย |
---|---|---|
date | Date | วันที่ล่าสุด |
รีเทิร์น
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. var sheet = SpreadsheetApp.getActiveSheet(); var range = sheet.getRange("A1:B3"); var rule = SpreadsheetApp.newConditionalFormatRule() .whenDateAfter(SpreadsheetApp.RelativeDate.TODAY) .setBackground("#FF0000") .setRanges([range]) .build(); var rules = sheet.getConditionalFormatRules(); rules.push(rule); sheet.setConditionalFormatRules(rules);
พารามิเตอร์
ชื่อ | Type | คำอธิบาย |
---|---|---|
date | RelativeDate | วันที่ล่าสุดที่เกี่ยวข้องกับประเภทวันที่ที่เลือก |
รีเทิร์น
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. var sheet = SpreadsheetApp.getActiveSheet(); var range = sheet.getRange("A1:B3"); var rule = SpreadsheetApp.newConditionalFormatRule() .whenDateBefore(new Date("11/4/1993")) .setBackground("#FF0000") .setRanges([range]) .build(); var rules = sheet.getConditionalFormatRules(); rules.push(rule); sheet.setConditionalFormatRules(rules);
พารามิเตอร์
ชื่อ | Type | คำอธิบาย |
---|---|---|
date | Date | วันที่แรกที่ยอมรับไม่ได้ |
รีเทิร์น
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. var sheet = SpreadsheetApp.getActiveSheet(); var range = sheet.getRange("A1:B3"); var rule = SpreadsheetApp.newConditionalFormatRule() .whenDateBefore(SpreadsheetApp.RelativeDate.TODAY) .setBackground("#FF0000") .setRanges([range]) .build(); var rules = sheet.getConditionalFormatRules(); rules.push(rule); sheet.setConditionalFormatRules(rules);
พารามิเตอร์
ชื่อ | Type | คำอธิบาย |
---|---|---|
date | RelativeDate | วันที่ล่าสุดที่เกี่ยวข้องกับประเภทวันที่ที่เลือก |
รีเทิร์น
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. var sheet = SpreadsheetApp.getActiveSheet(); var range = sheet.getRange("A1:B3"); var rule = SpreadsheetApp.newConditionalFormatRule() .whenDateEqualTo(new Date("11/4/1993")) .setBackground("#FF0000") .setRanges([range]) .build(); var rules = sheet.getConditionalFormatRules(); rules.push(rule); sheet.setConditionalFormatRules(rules);
พารามิเตอร์
ชื่อ | Type | คำอธิบาย |
---|---|---|
date | Date | วันที่ยอมรับเพียงอย่างเดียว |
รีเทิร์น
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. var sheet = SpreadsheetApp.getActiveSheet(); var range = sheet.getRange("A1:B3"); var rule = SpreadsheetApp.newConditionalFormatRule() .whenDateEqualTo(SpreadsheetApp.RelativeDate.TODAY) .setBackground("#FF0000") .setRanges([range]) .build(); var rules = sheet.getConditionalFormatRules(); rules.push(rule); sheet.setConditionalFormatRules(rules);
พารามิเตอร์
ชื่อ | Type | คำอธิบาย |
---|---|---|
date | RelativeDate | วันที่ล่าสุดที่เกี่ยวข้องกับประเภทวันที่ที่เลือก |
รีเทิร์น
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)". var sheet = SpreadsheetApp.getActiveSheet(); var range = sheet.getRange("A1:B3"); var rule = SpreadsheetApp.newConditionalFormatRule() .whenFormulaSatisfied("=EQ(B4, C3)") .setBackground("#FF0000") .setRanges([range]) .build(); var rules = sheet.getConditionalFormatRules(); rules.push(rule); sheet.setConditionalFormatRules(rules);
พารามิเตอร์
ชื่อ | Type | คำอธิบาย |
---|---|---|
formula | String | สูตรที่กำหนดเองซึ่งจะประเมินเป็น 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. var sheet = SpreadsheetApp.getActiveSheet(); var range = sheet.getRange("A1:B3"); var rule = SpreadsheetApp.newConditionalFormatRule() .whenNumberBetween(1, 10) .setBackground("#FF0000") .setRanges([range]) .build(); var rules = sheet.getConditionalFormatRules(); rules.push(rule); sheet.setConditionalFormatRules(rules);
พารามิเตอร์
ชื่อ | Type | คำอธิบาย |
---|---|---|
start | Number | ค่าต่ำสุดที่ยอมรับได้ |
end | Number | ค่าสูงสุดที่ยอมรับได้ |
รีเทิร์น
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. var sheet = SpreadsheetApp.getActiveSheet(); var range = sheet.getRange("A1:B3"); var rule = SpreadsheetApp.newConditionalFormatRule() .whenNumberEqualTo(10) .setBackground("#FF0000") .setRanges([range]) .build(); var rules = sheet.getConditionalFormatRules(); rules.push(rule); sheet.setConditionalFormatRules(rules);
พารามิเตอร์
ชื่อ | Type | คำอธิบาย |
---|---|---|
number | Number | ค่าที่ยอมรับได้เพียงค่าเดียว |
รีเทิร์น
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. var sheet = SpreadsheetApp.getActiveSheet(); var range = sheet.getRange("A1:B3"); var rule = SpreadsheetApp.newConditionalFormatRule() .whenNumberGreaterThan(10) .setBackground("#FF0000") .setRanges([range]) .build(); var rules = sheet.getConditionalFormatRules(); rules.push(rule); sheet.setConditionalFormatRules(rules);
พารามิเตอร์
ชื่อ | Type | คำอธิบาย |
---|---|---|
number | Number | ค่าสูงสุดที่ยอมรับไม่ได้ |
รีเทิร์น
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. var sheet = SpreadsheetApp.getActiveSheet(); var range = sheet.getRange("A1:B3"); var rule = SpreadsheetApp.newConditionalFormatRule() .whenNumberGreaterThanOrEqualTo(10) .setBackground("#FF0000") .setRanges([range]) .build(); var rules = sheet.getConditionalFormatRules(); rules.push(rule); sheet.setConditionalFormatRules(rules);
พารามิเตอร์
ชื่อ | Type | คำอธิบาย |
---|---|---|
number | Number | ค่าต่ำสุดที่ยอมรับได้ |
รีเทิร์น
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. var sheet = SpreadsheetApp.getActiveSheet(); var range = sheet.getRange("A1:B3"); var rule = SpreadsheetApp.newConditionalFormatRule() .whenNumberLessThan(10) .setBackground("#FF0000") .setRanges([range]) .build(); var rules = sheet.getConditionalFormatRules(); rules.push(rule); sheet.setConditionalFormatRules(rules);
พารามิเตอร์
ชื่อ | Type | คำอธิบาย |
---|---|---|
number | Number | ค่าต่ำสุดที่ยอมรับไม่ได้ |
รีเทิร์น
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. var sheet = SpreadsheetApp.getActiveSheet(); var range = sheet.getRange("A1:B3"); var rule = SpreadsheetApp.newConditionalFormatRule() .whenNumberLessThanOrEqualTo(10) .setBackground("#FF0000") .setRanges([range]) .build(); var rules = sheet.getConditionalFormatRules(); rules.push(rule); sheet.setConditionalFormatRules(rules);
พารามิเตอร์
ชื่อ | Type | คำอธิบาย |
---|---|---|
number | Number | ค่าสูงสุดที่ยอมรับได้ |
รีเทิร์น
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. var sheet = SpreadsheetApp.getActiveSheet(); var range = sheet.getRange("A1:B3"); var rule = SpreadsheetApp.newConditionalFormatRule() .whenNumberNotBetween(1, 10) .setBackground("#FF0000") .setRanges([range]) .build(); var rules = sheet.getConditionalFormatRules(); rules.push(rule); sheet.setConditionalFormatRules(rules);
พารามิเตอร์
ชื่อ | Type | คำอธิบาย |
---|---|---|
start | Number | ค่าต่ำสุดที่ยอมรับไม่ได้ |
end | Number | ค่าสูงสุดที่ยอมรับไม่ได้ |
รีเทิร์น
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. var sheet = SpreadsheetApp.getActiveSheet(); var range = sheet.getRange("A1:B3"); var rule = SpreadsheetApp.newConditionalFormatRule() .whenNumberNotEqualTo(10) .setBackground("#FF0000") .setRanges([range]) .build(); var rules = sheet.getConditionalFormatRules(); rules.push(rule); sheet.setConditionalFormatRules(rules);
พารามิเตอร์
ชื่อ | Type | คำอธิบาย |
---|---|---|
number | Number | ค่าที่ไม่ยอมรับเพียงอย่างเดียว |
รีเทิร์น
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". var sheet = SpreadsheetApp.getActiveSheet(); var range = sheet.getRange("A1:B3"); var rule = SpreadsheetApp.newConditionalFormatRule() .whenTextContains("hello") .setBackground("#FF0000") .setRanges([range]) .build(); var rules = sheet.getConditionalFormatRules(); rules.push(rule); sheet.setConditionalFormatRules(rules);
พารามิเตอร์
ชื่อ | Type | คำอธิบาย |
---|---|---|
text | String | ค่าที่ต้องมีในอินพุต |
รีเทิร์น
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". var sheet = SpreadsheetApp.getActiveSheet(); var range = sheet.getRange("A1:B3"); var rule = SpreadsheetApp.newConditionalFormatRule() .whenTextDoesNotContain("hello") .setBackground("#FF0000") .setRanges([range]) .build(); var rules = sheet.getConditionalFormatRules(); rules.push(rule); sheet.setConditionalFormatRules(rules);
พารามิเตอร์
ชื่อ | Type | คำอธิบาย |
---|---|---|
text | String | ค่าที่ต้องไม่มีอยู่ในอินพุต |
รีเทิร์น
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". var sheet = SpreadsheetApp.getActiveSheet(); var range = sheet.getRange("A1:B3"); var rule = SpreadsheetApp.newConditionalFormatRule() .whenTextEndsWith("hello") .setBackground("#FF0000") .setRanges([range]) .build(); var rules = sheet.getConditionalFormatRules(); rules.push(rule); sheet.setConditionalFormatRules(rules);
พารามิเตอร์
ชื่อ | Type | คำอธิบาย |
---|---|---|
text | String | ข้อความที่จะเปรียบเทียบกับส่วนท้ายของสตริง |
รีเทิร์น
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". var sheet = SpreadsheetApp.getActiveSheet(); var range = sheet.getRange("A1:B3"); var rule = SpreadsheetApp.newConditionalFormatRule() .whenTextEqualTo("hello") .setBackground("#FF0000") .setRanges([range]) .build(); var rules = sheet.getConditionalFormatRules(); rules.push(rule); sheet.setConditionalFormatRules(rules);
พารามิเตอร์
ชื่อ | Type | คำอธิบาย |
---|---|---|
text | String | ค่าที่ยอมรับได้เพียงค่าเดียว |
รีเทิร์น
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". var sheet = SpreadsheetApp.getActiveSheet(); var range = sheet.getRange("A1:B3"); var rule = SpreadsheetApp.newConditionalFormatRule() .whenTextStartsWith("hello") .setBackground("#FF0000") .setRanges([range]) .build(); var rules = sheet.getConditionalFormatRules(); rules.push(rule); sheet.setConditionalFormatRules(rules);
พารามิเตอร์
ชื่อ | Type | คำอธิบาย |
---|---|---|
text | String | ข้อความที่จะเปรียบเทียบกับจุดเริ่มต้นของสตริง |
รีเทิร์น
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. var sheet = SpreadsheetApp.getActiveSheet(); var rules = sheet.getConditionalFormatRules(); var booleanCondition = rules[0].getBooleanCondition(); if (booleanCondition != null) { var rule = SpreadsheetApp.newConditionalFormatRule() .withCriteria(booleanCondition.getCriteriaType(), booleanCondition.getCriteriaValues()) .setBackground("#000000") .setRanges(rule.getRanges()) .build(); rules.push(rule); } sheet.setConditionalFormatRules(rules);
พารามิเตอร์
ชื่อ | Type | คำอธิบาย |
---|---|---|
criteria | BooleanCriteria | ประเภทของเกณฑ์รูปแบบตามเงื่อนไข |
args | Object[] | อาร์เรย์ของอาร์กิวเมนต์ที่เหมาะกับประเภทเกณฑ์ จำนวนอาร์กิวเมนต์และประเภทตรงกับเมธอด when...() ที่เกี่ยวข้องข้างต้น |
รีเทิร์น
ConditionalFormatRuleBuilder
— เครื่องมือสร้างสำหรับการทำเชน