เครื่องมือสร้างกฎการจัดรูปแบบตามเงื่อนไข
// 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() | Conditional | สร้างกฎการจัดรูปแบบตามเงื่อนไขจากการตั้งค่าที่ใช้กับเครื่องมือสร้าง |
copy() | Conditional | แสดงค่าที่กำหนดล่วงหน้าของเครื่องมือสร้างกฎพร้อมการตั้งค่าของกฎนี้ |
get | Boolean | เรียกข้อมูล Boolean ของกฎหากกฎนี้ใช้ เกณฑ์เงื่อนไขบูลีน |
get | Gradient | เรียกข้อมูลGradient ของกฎ หากกฎนี้ ใช้เกณฑ์เงื่อนไขแบบไล่ระดับสี |
get | Range[] | เรียกข้อมูลช่วงที่ใช้กฎการจัดรูปแบบตามเงื่อนไขนี้ |
set | Conditional | ตั้งค่าสีพื้นหลังสำหรับรูปแบบของกฎการจัดรูปแบบตามเงื่อนไข |
set | Conditional | ตั้งค่าสีพื้นหลังสำหรับรูปแบบของกฎการจัดรูปแบบตามเงื่อนไข |
set | Conditional | ตั้งค่าการทำข้อความเป็นตัวหนาสำหรับรูปแบบของกฎการจัดรูปแบบตามเงื่อนไข |
set | Conditional | กำหนดสีแบบอักษรให้กับรูปแบบของกฎการจัดรูปแบบตามเงื่อนไข |
set | Conditional | กำหนดสีแบบอักษรให้กับรูปแบบของกฎการจัดรูปแบบตามเงื่อนไข |
set | Conditional | ล้างค่าจุดสูงสุดของการไล่ระดับสีของกฎการจัดรูปแบบตามเงื่อนไข และใช้ค่าสูงสุด ในช่วงของกฎแทน |
set | Conditional | ล้างค่าจุดสูงสุดของการไล่ระดับสีของกฎการจัดรูปแบบตามเงื่อนไข และใช้ค่าสูงสุด ในช่วงของกฎแทน |
set | Conditional | ตั้งค่าฟิลด์จุดสูงสุดของการไล่ระดับสีของกฎการจัดรูปแบบตามเงื่อนไข |
set | Conditional | ตั้งค่าฟิลด์จุดสูงสุดของการไล่ระดับสีของกฎการจัดรูปแบบตามเงื่อนไข |
set | Conditional | ตั้งค่าฟิลด์จุดกึ่งกลางของการไล่ระดับสีของกฎการจัดรูปแบบตามเงื่อนไข |
set | Conditional | ตั้งค่าฟิลด์จุดกึ่งกลางของการไล่ระดับสีของกฎการจัดรูปแบบตามเงื่อนไข |
set | Conditional | ล้างค่าจุดต่ำสุดของเส้นไล่ระดับสีของกฎการจัดรูปแบบตามเงื่อนไข และใช้ค่าต่ำสุด ในขอบเขตของกฎแทน |
set | Conditional | ล้างค่าจุดต่ำสุดของเส้นไล่ระดับสีของกฎการจัดรูปแบบตามเงื่อนไข และใช้ค่าต่ำสุด ในขอบเขตของกฎแทน |
set | Conditional | ตั้งค่าฟิลด์จุดต่ำสุดของเส้นไล่ระดับของกฎการจัดรูปแบบตามเงื่อนไข |
set | Conditional | ตั้งค่าฟิลด์จุดต่ำสุดของเส้นไล่ระดับของกฎการจัดรูปแบบตามเงื่อนไข |
set | Conditional | กำหนดให้ข้อความเป็นตัวเอียงสำหรับรูปแบบของกฎการจัดรูปแบบตามเงื่อนไข |
set | Conditional | ตั้งค่าช่วงอย่างน้อย 1 ช่วงที่จะใช้กฎการจัดรูปแบบตามเงื่อนไขนี้ |
set | Conditional | กำหนดขีดทับข้อความสำหรับรูปแบบของกฎการจัดรูปแบบตามเงื่อนไข |
set | Conditional | กำหนดการขีดเส้นใต้ข้อความสำหรับรูปแบบของกฎการจัดรูปแบบตามเงื่อนไข |
when | Conditional | ตั้งค่ากฎการจัดรูปแบบตามเงื่อนไขให้ทริกเกอร์เมื่อเซลล์ว่าง |
when | Conditional | ตั้งค่ากฎการจัดรูปแบบตามเงื่อนไขให้ทริกเกอร์เมื่อเซลล์ไม่ว่าง |
when | Conditional | ตั้งค่ากฎการจัดรูปแบบตามเงื่อนไขให้ทริกเกอร์เมื่อวันที่อยู่หลังค่าที่ระบุ |
when | Conditional | ตั้งค่ากฎการจัดรูปแบบตามเงื่อนไขให้ทริกเกอร์เมื่อวันที่อยู่หลังวันที่สัมพัทธ์ที่ระบุ |
when | Conditional | ตั้งค่ากฎการจัดรูปแบบตามเงื่อนไขให้ทริกเกอร์เมื่อวันที่อยู่ก่อนวันที่ที่ระบุ |
when | Conditional | ตั้งค่ากฎการจัดรูปแบบตามเงื่อนไขให้ทริกเกอร์เมื่อวันที่อยู่ก่อนวันที่สัมพัทธ์ที่ระบุ |
when | Conditional | ตั้งค่ากฎการจัดรูปแบบตามเงื่อนไขให้ทริกเกอร์เมื่อวันที่เท่ากับวันที่ที่ระบุ |
when | Conditional | ตั้งค่ากฎการจัดรูปแบบตามเงื่อนไขให้ทริกเกอร์เมื่อวันที่เท่ากับวันที่สัมพัทธ์ที่ระบุ |
when | Conditional | กำหนดกฎการจัดรูปแบบตามเงื่อนไขให้ทริกเกอร์เมื่อสูตรที่ระบุให้ค่าเป็น true |
when | Conditional | ตั้งค่ากฎการจัดรูปแบบตามเงื่อนไขให้ทริกเกอร์เมื่อตัวเลขอยู่ระหว่างหรือเป็นค่าใดค่าหนึ่งของค่าที่ระบุ 2 ค่า |
when | Conditional | ตั้งค่ากฎการจัดรูปแบบตามเงื่อนไขให้ทริกเกอร์เมื่อตัวเลขเท่ากับค่าที่ระบุ |
when | Conditional | กำหนดกฎการจัดรูปแบบตามเงื่อนไขให้ทริกเกอร์เมื่อตัวเลขมากกว่าค่าที่ระบุ |
when | Conditional | ตั้งค่ากฎการจัดรูปแบบตามเงื่อนไขให้ทริกเกอร์เมื่อตัวเลขมากกว่าหรือเท่ากับค่าที่ระบุ |
when | Conditional | ตั้งค่ากฎการจัดรูปแบบตามเงื่อนไขให้ทริกเกอร์เมื่อตัวเลขน้อยกว่าค่าที่ระบุ |
when | Conditional | ตั้งค่ากฎการจัดรูปแบบตามเงื่อนไขให้ทริกเกอร์เมื่อตัวเลขน้อยกว่าหรือเท่ากับค่าที่ระบุ |
when | Conditional | ตั้งค่ากฎการจัดรูปแบบตามเงื่อนไขให้ทริกเกอร์เมื่อตัวเลขไม่ได้อยู่ระหว่างค่าที่ระบุ 2 ค่า และไม่ใช่ค่าใดค่าหนึ่ง |
when | Conditional | กำหนดกฎการจัดรูปแบบตามเงื่อนไขให้ทริกเกอร์เมื่อตัวเลขไม่เท่ากับค่าที่ระบุ |
when | Conditional | ตั้งค่ากฎการจัดรูปแบบตามเงื่อนไขให้ทริกเกอร์เมื่ออินพุตมีค่าที่ระบุ |
when | Conditional | ตั้งค่ากฎการจัดรูปแบบตามเงื่อนไขให้ทริกเกอร์เมื่ออินพุตไม่มีค่าที่ระบุ |
when | Conditional | ตั้งค่ากฎการจัดรูปแบบตามเงื่อนไขให้ทริกเกอร์เมื่ออินพุตลงท้ายด้วยค่าที่ระบุ |
when | Conditional | ตั้งค่ากฎการจัดรูปแบบตามเงื่อนไขให้ทริกเกอร์เมื่ออินพุตเท่ากับค่าที่ระบุ |
when | Conditional | ตั้งค่ากฎการจัดรูปแบบตามเงื่อนไขให้ทริกเกอร์เมื่ออินพุตเริ่มต้นด้วยค่าที่ระบุ |
with | Conditional | ตั้งค่ากฎการจัดรูปแบบตามเงื่อนไขเป็นเกณฑ์ที่กำหนดโดยค่า Boolean ซึ่งโดยปกติจะมาจาก criteria และ arguments ของกฎที่มีอยู่ |
เอกสารโดยละเอียด
build()
สร้างกฎการจัดรูปแบบตามเงื่อนไขจากการตั้งค่าที่ใช้กับเครื่องมือสร้าง
รีเทิร์น
Conditional
— การแสดงกฎการจัดรูปแบบตามเงื่อนไข
copy()
แสดงค่าที่กำหนดล่วงหน้าของเครื่องมือสร้างกฎพร้อมการตั้งค่าของกฎนี้
รีเทิร์น
Conditional
- ตัวสร้างที่อิงตามการตั้งค่าของกฎนี้
get Boolean Condition()
เรียกข้อมูล Boolean
ของกฎหากกฎนี้ใช้ เกณฑ์เงื่อนไขบูลีน ไม่เช่นนั้นจะแสดงผล 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()); }
รีเทิร์น
Boolean
- ออบเจ็กต์เงื่อนไขบูลีน หรือ null
หากกฎไม่ได้ใช้เงื่อนไขบูลีน
get Gradient Condition()
เรียกข้อมูลGradient
ของกฎ หากกฎนี้ ใช้เกณฑ์เงื่อนไขแบบไล่ระดับสี ไม่เช่นนั้นจะแสดงผล 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()); }
รีเทิร์น
Gradient
— ออบเจ็กต์เงื่อนไขการไล่ระดับสี หรือ null
หากกฎไม่ได้ใช้เงื่อนไขการไล่ระดับสี
get Ranges()
เรียกข้อมูลช่วงที่ใช้กฎการจัดรูปแบบตามเงื่อนไขนี้
// 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[]
— ช่วงที่ใช้กฎการจัดรูปแบบตามเงื่อนไขนี้
set Background(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);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
color | String | สีที่ต้องการหรือ null เพื่อล้าง |
รีเทิร์น
Conditional
— ตัวสร้างสำหรับการเชื่อมโยง
set Background Object(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);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
color | Color | ออบเจ็กต์สีที่ต้องการหรือ null เพื่อล้าง |
รีเทิร์น
Conditional
— ตัวสร้างสำหรับการเชื่อมโยง
set Bold(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);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
bold | Boolean | จะทำตัวหนาข้อความหรือไม่หากตรงตามเงื่อนไขรูปแบบ null จะนำการตั้งค่านี้ออก |
รีเทิร์น
Conditional
— ตัวสร้างสำหรับการเชื่อมโยง
set Font Color(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);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
color | String | สีที่ต้องการหรือ null เพื่อล้าง |
รีเทิร์น
Conditional
— ตัวสร้างสำหรับการเชื่อมโยง
set Font Color Object(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);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
color | Color | ออบเจ็กต์สีที่ต้องการหรือ null เพื่อล้าง |
รีเทิร์น
Conditional
— ตัวสร้างสำหรับการเชื่อมโยง
set Gradient Maxpoint(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);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
color | String | สีของค่าสูงสุดที่จะตั้ง |
รีเทิร์น
Conditional
— ตัวสร้างสำหรับการเชื่อมโยง
set Gradient Maxpoint Object(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);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
color | Color | ออบเจ็กต์สีของค่าสูงสุดที่จะตั้งค่า |
รีเทิร์น
Conditional
— ตัวสร้างสำหรับการเชื่อมโยง
set Gradient Maxpoint Object With Value(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);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
color | Color | สีของค่าสูงสุดที่จะตั้ง |
type | Interpolation | ประเภทการประมาณค่าสูงสุดที่จะตั้งค่า |
value | String | ค่าสูงสุดที่จะตั้ง |
รีเทิร์น
Conditional
— ตัวสร้างสำหรับการเชื่อมโยง
set Gradient Maxpoint With Value(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);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
color | String | สีของค่าสูงสุดที่จะตั้ง |
type | Interpolation | ประเภทการประมาณค่าสูงสุดที่จะตั้งค่า |
value | String | ค่าสูงสุดที่จะตั้ง |
รีเทิร์น
Conditional
— ตัวสร้างสำหรับการเชื่อมโยง
set Gradient Midpoint Object With Value(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);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
color | Color | สีจุดกึ่งกลางที่จะตั้งค่า |
type | Interpolation | ประเภทการประมาณค่ากึ่งกลางที่จะตั้งค่าหรือ null เพื่อล้าง |
value | String | ค่ากลางที่จะตั้ง |
รีเทิร์น
Conditional
— ตัวสร้างสำหรับการเชื่อมโยง
set Gradient Midpoint With Value(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);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
color | String | สีจุดกึ่งกลางที่จะตั้งค่า |
type | Interpolation | ประเภทการประมาณค่ากึ่งกลางที่จะตั้งค่าหรือ null เพื่อล้าง |
value | String | ค่ากลางที่จะตั้ง |
รีเทิร์น
Conditional
— ตัวสร้างสำหรับการเชื่อมโยง
set Gradient Minpoint(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);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
color | String | สีของจุดต่ำสุดที่จะตั้งค่า |
รีเทิร์น
Conditional
— ตัวสร้างสำหรับการเชื่อมโยง
set Gradient Minpoint Object(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);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
color | Color | ออบเจ็กต์สีของจุดต่ำสุดที่จะตั้งค่า |
รีเทิร์น
Conditional
— ตัวสร้างสำหรับการเชื่อมโยง
set Gradient Minpoint Object With Value(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);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
color | Color | สีของจุดต่ำสุดที่จะตั้งค่า |
type | Interpolation | ประเภทการประมาณค่า minpoint ที่จะตั้งค่า |
value | String | ค่าต่ำสุดที่จะตั้ง |
รีเทิร์น
Conditional
— ตัวสร้างสำหรับการเชื่อมโยง
set Gradient Minpoint With Value(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);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
color | String | สีของจุดต่ำสุดที่จะตั้งค่า |
type | Interpolation | ประเภทการประมาณค่า minpoint ที่จะตั้งค่า |
value | String | ค่าต่ำสุดที่จะตั้ง |
รีเทิร์น
Conditional
— ตัวสร้างสำหรับการเชื่อมโยง
set Italic(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);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
italic | Boolean | ไม่ว่าจะควรทำตัวเอียงข้อความหรือไม่หากตรงตามเงื่อนไขรูปแบบ null จะนำการตั้งค่านี้ออก |
รีเทิร์น
Conditional
— ตัวสร้างสำหรับการเชื่อมโยง
set Ranges(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);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
ranges | Range[] | ช่วงที่ใช้กฎการจัดรูปแบบตามเงื่อนไขนี้ |
รีเทิร์น
Conditional
— ตัวสร้างสำหรับการเชื่อมโยง
set Strikethrough(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);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
strikethrough | Boolean | จะขีดทับข้อความหรือไม่หากตรงตามเงื่อนไขรูปแบบ null จะนำการตั้งค่านี้ออก |
รีเทิร์น
Conditional
— ตัวสร้างสำหรับการเชื่อมโยง
set Underline(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);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
underline | Boolean | จะขีดเส้นใต้ข้อความหรือไม่หากตรงตามเงื่อนไขรูปแบบ null จะนำการตั้งค่านี้ออก |
รีเทิร์น
Conditional
— ตัวสร้างสำหรับการเชื่อมโยง
when Cell Empty()
ตั้งค่ากฎการจัดรูปแบบตามเงื่อนไขให้ทริกเกอร์เมื่อเซลล์ว่าง
// 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);
รีเทิร์น
Conditional
— ตัวสร้างสำหรับการเชื่อมโยง
when Cell Not Empty()
ตั้งค่ากฎการจัดรูปแบบตามเงื่อนไขให้ทริกเกอร์เมื่อเซลล์ไม่ว่าง
// 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);
รีเทิร์น
Conditional
— ตัวสร้างสำหรับการเชื่อมโยง
when Date After(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);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
date | Date | วันที่ล่าสุด |
รีเทิร์น
Conditional
— ตัวสร้างสำหรับการเชื่อมโยง
when Date After(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);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
date | Relative | วันที่ล่าสุดที่เกี่ยวข้องกับประเภทวันที่ที่เลือก |
รีเทิร์น
Conditional
— ตัวสร้างสำหรับการเชื่อมโยง
when Date Before(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);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
date | Date | วันที่เร็วที่สุดที่ยอมรับไม่ได้ |
รีเทิร์น
Conditional
— ตัวสร้างสำหรับการเชื่อมโยง
when Date Before(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);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
date | Relative | วันที่ล่าสุดที่เกี่ยวข้องกับประเภทวันที่ที่เลือก |
รีเทิร์น
Conditional
— ตัวสร้างสำหรับการเชื่อมโยง
when Date Equal To(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);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
date | Date | วันที่ที่ยอมรับได้เพียงวันเดียว |
รีเทิร์น
Conditional
— ตัวสร้างสำหรับการเชื่อมโยง
when Date Equal To(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);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
date | Relative | วันที่ล่าสุดที่เกี่ยวข้องกับประเภทวันที่ที่เลือก |
รีเทิร์น
Conditional
— ตัวสร้างสำหรับการเชื่อมโยง
when Formula Satisfied(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);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
formula | String | สูตรที่กำหนดเองซึ่งประเมินเป็น true หากอินพุตถูกต้อง |
รีเทิร์น
Conditional
— ตัวสร้างสำหรับการเชื่อมโยง
when Number Between(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);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
start | Number | ค่าต่ำสุดที่ยอมรับได้ |
end | Number | ค่าสูงสุดที่ยอมรับได้ |
รีเทิร์น
Conditional
— ตัวสร้างสำหรับการเชื่อมโยง
when Number Equal To(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);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
number | Number | ค่าที่ยอมรับเพียงค่าเดียว |
รีเทิร์น
Conditional
— ตัวสร้างสำหรับการเชื่อมโยง
when Number Greater Than(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);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
number | Number | ค่าสูงสุดที่ยอมรับไม่ได้ |
รีเทิร์น
Conditional
— ตัวสร้างสำหรับการเชื่อมโยง
when Number Greater Than Or Equal To(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);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
number | Number | ค่าต่ำสุดที่ยอมรับได้ |
รีเทิร์น
Conditional
— ตัวสร้างสำหรับการเชื่อมโยง
when Number Less Than(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);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
number | Number | ค่าต่ำสุดที่ยอมรับไม่ได้ |
รีเทิร์น
Conditional
— ตัวสร้างสำหรับการเชื่อมโยง
when Number Less Than Or Equal To(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);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
number | Number | ค่าสูงสุดที่ยอมรับได้ |
รีเทิร์น
Conditional
— ตัวสร้างสำหรับการเชื่อมโยง
when Number Not Between(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);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
start | Number | ค่าต่ำสุดที่ยอมรับไม่ได้ |
end | Number | ค่าสูงสุดที่ยอมรับไม่ได้ |
รีเทิร์น
Conditional
— ตัวสร้างสำหรับการเชื่อมโยง
when Number Not Equal To(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);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
number | Number | ค่าเดียวที่ยอมรับไม่ได้ |
รีเทิร์น
Conditional
— ตัวสร้างสำหรับการเชื่อมโยง
when Text Contains(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);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
text | String | ค่าที่อินพุตต้องมี |
รีเทิร์น
Conditional
— ตัวสร้างสำหรับการเชื่อมโยง
when Text Does Not Contain(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);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
text | String | ค่าที่อินพุตต้องไม่มี |
รีเทิร์น
Conditional
— ตัวสร้างสำหรับการเชื่อมโยง
when Text Ends With(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);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
text | String | ข้อความที่จะเปรียบเทียบกับส่วนท้ายของสตริง |
รีเทิร์น
Conditional
— ตัวสร้างสำหรับการเชื่อมโยง
when Text Equal To(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);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
text | String | ค่าที่ยอมรับเพียงค่าเดียว |
รีเทิร์น
Conditional
— ตัวสร้างสำหรับการเชื่อมโยง
when Text Starts With(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);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
text | String | ข้อความที่จะเปรียบเทียบกับจุดเริ่มต้นของสตริง |
รีเทิร์น
Conditional
— ตัวสร้างสำหรับการเชื่อมโยง
with Criteria(criteria, args)
ตั้งค่ากฎการจัดรูปแบบตามเงื่อนไขเป็นเกณฑ์ที่กำหนดโดยค่า Boolean
ซึ่งโดยปกติจะมาจาก 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);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
criteria | Boolean | ประเภทของเกณฑ์การจัดรูปแบบตามเงื่อนไข |
args | Object[] | อาร์กิวเมนต์อาร์เรย์ที่เหมาะสมกับประเภทเกณฑ์ จำนวนอาร์กิวเมนต์และ ประเภทของอาร์กิวเมนต์ตรงกับwhen...() เมธอดที่เกี่ยวข้องด้านบน |
รีเทิร์น
Conditional
— ตัวสร้างสำหรับการเชื่อมโยง