條件式格式規則的建構工具。
// 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()
copy()
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 | 要設定的 maxpoint 插補類型。 |
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 | 要設定的 maxpoint 插補類型。 |
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)
設定要套用這項條件式格式規則的一或多個範圍。這項作業會取代現有的範圍。設定空陣列會清除所有現有範圍。規則必須至少有一個範圍。
// 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)
設定條件式格式規則,當數字介於兩個指定值之間或等於其中一個值時,就會觸發規則。
// 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)
設定條件式格式規則,當數字不介於兩個指定值之間,且不等於這兩個值時觸發。
// 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
:用於鏈結的建構工具。