条件付き書式設定ルールのビルダー。
// 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 | 設定する maxpoint 値。 |
戻る
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 | 設定する maxpoint 値。 |
戻る
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 | 設定する最小ポイント補間タイプ。 |
value | String | 設定する minpoint 値。 |
戻る
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 | 設定する最小ポイント補間タイプ。 |
value | String | 設定する minpoint 値。 |
戻る
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
- チェーン用のビルダー。