Class ConditionalFormatRuleBuilder

ConditionalFormatRuleBuilder

条件付き書式ルールのビルダー。

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

Methods

メソッド戻り値の型概要
build()ConditionalFormatRuleビルダーに適用されている設定から条件付き書式ルールを作成します。
copy()ConditionalFormatRuleBuilderこのルールの設定を含むルール作成ツールのプリセットを返します。
getBooleanCondition()BooleanConditionこのルールがブール条件条件を使用する場合、ルールの BooleanCondition 情報を取得します。
getGradientCondition()GradientConditionこのルールでグラデーション条件の条件を使用する場合は、ルールの GradientCondition 情報を取得します。
getRanges()Range[]この条件付き書式ルールが適用される範囲を取得します。
setBackground(color)ConditionalFormatRuleBuilder条件付き書式ルールの書式の背景色を設定します。
setBackgroundObject(color)ConditionalFormatRuleBuilder条件付き書式ルールの書式の背景色を設定します。
setBold(bold)ConditionalFormatRuleBuilder条件付き書式ルールの書式にテキストを太字にします。
setFontColor(color)ConditionalFormatRuleBuilder条件付き書式ルールの書式のフォントの色を設定します。
setFontColorObject(color)ConditionalFormatRuleBuilder条件付き書式ルールの書式のフォントの色を設定します。
setGradientMaxpoint(color)ConditionalFormatRuleBuilder条件付き書式ルールのグラデーションの最大値をクリアし、ルールの範囲の最大値を使用します。
setGradientMaxpointObject(color)ConditionalFormatRuleBuilder条件付き書式ルールのグラデーションの最大値をクリアし、ルールの範囲の最大値を使用します。
setGradientMaxpointObjectWithValue(color, type, value)ConditionalFormatRuleBuilder条件付き書式ルールのグラデーションの maxpoint フィールドを設定します。
setGradientMaxpointWithValue(color, type, value)ConditionalFormatRuleBuilder条件付き書式ルールのグラデーションの maxpoint フィールドを設定します。
setGradientMidpointObjectWithValue(color, type, value)ConditionalFormatRuleBuilder条件付き書式ルールのグラデーションの中点フィールドを設定します。
setGradientMidpointWithValue(color, type, value)ConditionalFormatRuleBuilder条件付き書式ルールのグラデーションの中点フィールドを設定します。
setGradientMinpoint(color)ConditionalFormatRuleBuilder条件付き書式ルールのグラデーションの最小値をクリアし、ルールの範囲の最小値を使用します。
setGradientMinpointObject(color)ConditionalFormatRuleBuilder条件付き書式ルールのグラデーションの最小値をクリアし、ルールの範囲の最小値を使用します。
setGradientMinpointObjectWithValue(color, type, value)ConditionalFormatRuleBuilder条件付き書式ルールのグラデーションの最小点フィールドを設定します。
setGradientMinpointWithValue(color, type, value)ConditionalFormatRuleBuilder条件付き書式ルールのグラデーションの最小点フィールドを設定します。
setItalic(italic)ConditionalFormatRuleBuilder条件付き書式ルールの書式にテキストを斜体に設定します。
setRanges(ranges)ConditionalFormatRuleBuilderこの条件付き書式ルールを適用する範囲を 1 つ以上設定します。
setStrikethrough(strikethrough)ConditionalFormatRuleBuilder条件付き書式ルールの書式に取り消し線を設定します。
setUnderline(underline)ConditionalFormatRuleBuilder条件付き書式ルールの書式に下線を引くテキストを設定します。
whenCellEmpty()ConditionalFormatRuleBuilderセルが空の場合にトリガーされる条件付き書式ルールを設定します。
whenCellNotEmpty()ConditionalFormatRuleBuilderセルが空でない場合にトリガーされる条件付き書式ルールを設定します。
whenDateAfter(date)ConditionalFormatRuleBuilder日付が指定値より後の場合にトリガーされる条件付き書式ルールを設定します。
whenDateAfter(date)ConditionalFormatRuleBuilder日付が指定された相対日付より後の場合にトリガーされる条件付き書式ルールを設定します。
whenDateBefore(date)ConditionalFormatRuleBuilder日付が指定した日付よりも前の場合にトリガーされる条件付き書式ルールを設定します。
whenDateBefore(date)ConditionalFormatRuleBuilder日付が指定された相対日付よりも前の場合にトリガーされる条件付き書式ルールを設定します。
whenDateEqualTo(date)ConditionalFormatRuleBuilder日付が指定した日付と等しい場合にトリガーされる条件付き書式ルールを設定します。
whenDateEqualTo(date)ConditionalFormatRuleBuilder日付が指定された相対日付と等しい場合にトリガーされる条件付き書式ルールを設定します。
whenFormulaSatisfied(formula)ConditionalFormatRuleBuilder指定された式が true と評価されたときにトリガーされる条件付き書式ルールを設定します。
whenNumberBetween(start, end)ConditionalFormatRuleBuilder数値が指定された 2 つの値の間または指定された値のいずれかに該当する場合にトリガーする条件付き書式ルールを設定します。
whenNumberEqualTo(number)ConditionalFormatRuleBuilder数値が指定された値と等しい場合にトリガーする条件付き書式ルールを設定します。
whenNumberGreaterThan(number)ConditionalFormatRuleBuilder数値が指定された値より大きい場合にトリガーする条件付き書式ルールを設定します。
whenNumberGreaterThanOrEqualTo(number)ConditionalFormatRuleBuilder数値が指定された値以上になったときにトリガーする条件付き書式ルールを設定します。
whenNumberLessThan(number)ConditionalFormatRuleBuilder数値が指定された値より小さい場合にトリガーされる条件付き条件付き書式ルールを設定します。
whenNumberLessThanOrEqualTo(number)ConditionalFormatRuleBuilder数値が指定された値以下の場合にトリガーされる条件付き書式ルールを設定します。
whenNumberNotBetween(start, end)ConditionalFormatRuleBuilder指定した 2 つの値の間で数値が一致しない場合にトリガーされる条件付き書式ルールを設定します。
whenNumberNotEqualTo(number)ConditionalFormatRuleBuilder数値が指定された値と等しくない場合にトリガーされる条件付き書式ルールを設定します。
whenTextContains(text)ConditionalFormatRuleBuilder入力に指定値が含まれる場合にトリガーする条件付き書式ルールを設定します。
whenTextDoesNotContain(text)ConditionalFormatRuleBuilder入力に指定された値が含まれていない場合にトリガーする条件付き書式ルールを設定します。
whenTextEndsWith(text)ConditionalFormatRuleBuilder入力が指定された値で終了したときにトリガーする条件付き書式ルールを設定します。
whenTextEqualTo(text)ConditionalFormatRuleBuilder入力が指定された値と等しい場合にトリガーされる条件付き書式ルールを設定します。
whenTextStartsWith(text)ConditionalFormatRuleBuilder入力が指定された値で開始されたときにトリガーする条件付き書式ルールを設定します。
withCriteria(criteria, args)ConditionalFormatRuleBuilder条件付き書式ルールを、BooleanCriteria 値で定義された条件に設定します。通常は、既存のルールの criteriaarguments から取得されます。

詳細なドキュメント

build()

ビルダーに適用されている設定から条件付き書式ルールを作成します。

リターン

ConditionalFormatRule - 条件付き書式ルールの表現


copy()

このルールの設定を含むルール作成ツールのプリセットを返します。

リターン

ConditionalFormatRuleBuilder - このルールの設定に基づくビルダー


getBooleanCondition()

このルールがブール条件条件を使用する場合、ルールの BooleanCondition 情報を取得します。それ以外の場合は、null を返します。

// Log the boolean criteria type of the first conditional format rules of a sheet.
var rule = SpreadsheetApp.getActiveSheet().getConditionalFormatRules()[0];
var booleanCondition = rule.getBooleanCondition();
if (booleanCondition != null) {
  Logger.log(booleanCondition.getCriteriaType());
}

リターン

BooleanCondition - ブール条件オブジェクト。ルールがブール条件を使用しない場合は null


getGradientCondition()

このルールでグラデーション条件の条件を使用する場合は、ルールの GradientCondition 情報を取得します。それ以外の場合は、null を返します。

// Log the gradient minimum color of the first conditional format rule of a sheet.
var rule = SpreadsheetApp.getActiveSheet().getConditionalFormatRules()[0];
var gradientCondition = rule.getGradientCondition();
if (gradientCondition != null) {
  // Assume the color has ColorType.RGB.
  Logger.log(gradientCondition.getMinColorObject().asRgbColor().asHexString());
}

リターン

GradientCondition - グラデーション条件オブジェクト。ルールでグラデーション条件を使用しない場合は null


getRanges()

この条件付き書式ルールが適用される範囲を取得します。

// Log each range of the first conditional format rule of a sheet.
var rule = SpreadsheetApp.getActiveSheet().getConditionalFormatRules()[0];
var ranges = rule.getRanges();
for (var i = 0; i < ranges.length; i++) {
  Logger.log(ranges[i].getA1Notation());
}

リターン

Range[] - この条件付き書式ルールが適用される範囲。


setBackground(color)

条件付き書式ルールの書式の背景色を設定します。null を渡すと、背景色フォーマットの設定がルールから削除されます。

// Adds a conditional format rule to a sheet that causes cells in range A1:B3 to set their
// background color to red if the cell has text equal to "hello".

var sheet = SpreadsheetApp.getActiveSheet();
var range = sheet.getRange("A1:B3");
var rule = SpreadsheetApp.newConditionalFormatRule()
    .whenTextEqualTo("hello")
    .setBackground("#FF0000")
    .setRanges([range])
    .build();
var rules = sheet.getConditionalFormatRules();
rules.push(rule);
sheet.setConditionalFormatRules(rules);

パラメータ

名前説明
colorString消去する色または null

リターン

ConditionalFormatRuleBuilder - チェーン用のビルダー


setBackgroundObject(color)

条件付き書式ルールの書式の背景色を設定します。null を渡すと、背景色フォーマットの設定がルールから削除されます。

// Adds a conditional format rule to a sheet that causes cells in range A1:B3 to set their
// background color to theme background color if the cell has text equal to "hello".

var sheet = SpreadsheetApp.getActiveSheet();
var range = sheet.getRange("A1:B3");
var color = SpreadsheetApp.newColor()
    .setThemeColor(SpreadsheetApp.ThemeColorType.BACKGROUND)
    .build();
var rule = SpreadsheetApp.newConditionalFormatRule()
    .whenTextEqualTo("hello")
    .setBackground(color)
    .setRanges([range])
    .build();
var rules = sheet.getConditionalFormatRules();
rules.push(rule);
sheet.setConditionalFormatRules(rules);

パラメータ

名前説明
colorColor消去するカラー オブジェクトまたは null

リターン

ConditionalFormatRuleBuilder - チェーン用のビルダー。


setBold(bold)

条件付き書式ルールの書式にテキストを太字にします。boldtrue の場合、条件が満たされると、ルールはテキストを太字にします。false の場合、条件が満たされると既存の太字を削除します。null を渡すと、ルールから太字の設定が削除されます。

// Adds a conditional format rule to a sheet that causes cells in range A1:B3 to turn their
// text bold if the cell has text equal to "hello".

var sheet = SpreadsheetApp.getActiveSheet();
var range = sheet.getRange("A1:B3");
var rule = SpreadsheetApp.newConditionalFormatRule()
    .whenTextEqualTo("hello")
    .setBold(true)
    .setRanges([range])
    .build();
var rules = sheet.getConditionalFormatRules();
rules.push(rule);
sheet.setConditionalFormatRules(rules);

パラメータ

名前説明
boldBoolean書式設定の条件が満たされた場合にテキストを太字にするかどうかを指定します。null を使用すると、この設定が削除されます。

リターン

ConditionalFormatRuleBuilder - チェーン用のビルダー


setFontColor(color)

条件付き書式ルールの書式のフォントの色を設定します。null を渡すと、フォントカラー形式の設定がルールから削除されます。

// Adds a conditional format rule to a sheet that causes cells in range A1:B3 to set their font
// color to red if the cell has text equal to "hello".

var sheet = SpreadsheetApp.getActiveSheet();
var range = sheet.getRange("A1:B3");
var rule = SpreadsheetApp.newConditionalFormatRule()
    .whenTextEqualTo("hello")
    .setFontColor("#FF0000")
    .setRanges([range])
    .build();
var rules = sheet.getConditionalFormatRules();
rules.push(rule);
sheet.setConditionalFormatRules(rules);

パラメータ

名前説明
colorString消去する色または null

リターン

ConditionalFormatRuleBuilder - チェーン用のビルダー


setFontColorObject(color)

条件付き書式ルールの書式のフォントの色を設定します。null を渡すと、フォントカラー形式の設定がルールから削除されます。

// Adds a conditional format rule to a sheet that causes cells in range A1:B3 to set their font
// color to theme text color if the cell has text equal to "hello".

var sheet = SpreadsheetApp.getActiveSheet();
var range = sheet.getRange("A1:B3");
var color = SpreadsheetApp.newColor()
    .setThemeColor(SpreadsheetApp.ThemeColorType.TEXT)
    .build();
var rule = SpreadsheetApp.newConditionalFormatRule()
    .whenTextEqualTo("hello")
    .setFontColor(color)
    .setRanges([range])
    .build();
var rules = sheet.getConditionalFormatRules();
rules.push(rule);
sheet.setConditionalFormatRules(rules);

パラメータ

名前説明
colorColor消去するカラー オブジェクトまたは null

リターン

ConditionalFormatRuleBuilder - チェーン用のビルダー。


setGradientMaxpoint(color)

条件付き書式ルールのグラデーションの最大値をクリアし、ルールの範囲の最大値を使用します。また、グラデーションの maxpoint 色を入力色に設定します。

// Adds a conditional format rule to a sheet that causes cells in range A1:B3 to set their
// background color somewhere between white and red, based on their values in comparison to
// the ranges minimum and maximum values.

var sheet = SpreadsheetApp.getActiveSheet();
var range = sheet.getRange("A1:B3");
var rule = SpreadsheetApp.newConditionalFormatRule()
    .setGradientMaxpoint("#FF0000")
    .setGradientMinpoint("#FFFFFF")
    .setRanges([range])
    .build();
var rules = sheet.getConditionalFormatRules();
rules.push(rule);
sheet.setConditionalFormatRules(rules);

パラメータ

名前説明
colorString設定する最大ポイントの色。

リターン

ConditionalFormatRuleBuilder - チェーン用のビルダー


setGradientMaxpointObject(color)

条件付き書式ルールのグラデーションの最大値をクリアし、ルールの範囲の最大値を使用します。また、グラデーションの maxpoint 色を入力色に設定します。

// Adds a conditional format rule to a sheet that causes cells in range A1:B3 to set their
// background color somewhere between theme text and background colors, based on their values
// in comparison to the ranges minimum and maximum values.

var sheet = SpreadsheetApp.getActiveSheet();
var range = sheet.getRange("A1:B3");
var textColor = SpreadsheetApp.newColor()
    .setThemeColor(SpreadsheetApp.ThemeColorType.TEXT)
    .build();
var backgroundColor = SpreadsheetApp.newColor()
    .setThemeColor(SpreadsheetApp.ThemeColorType.BACKGROUND)
    .build();
var rule = SpreadsheetApp.newConditionalFormatRule()
    .setGradientMaxpoint(textColor)
    .setGradientMinpoint(backgroundColor)
    .setRanges([range])
    .build();
var rules = sheet.getConditionalFormatRules();
rules.push(rule);
sheet.setConditionalFormatRules(rules);

パラメータ

名前説明
colorColor設定する maxpoint カラー オブジェクト。

リターン

ConditionalFormatRuleBuilder - チェーン用のビルダー。


setGradientMaxpointObjectWithValue(color, type, value)

条件付き書式ルールのグラデーションの maxpoint フィールドを設定します。

// Adds a conditional format rule to a sheet that causes cells in range A1:B3 to set their
// background color somewhere from theme accent 1, accent 2 to accent 3 colors, based on their
// values in comparison to the values 0, 50, and 100.

var sheet = SpreadsheetApp.getActiveSheet();
var range = sheet.getRange("A1:B3");
var color1 = SpreadsheetApp.newColor()
    .setThemeColor(SpreadsheetApp.ThemeColorType.ACCENT1)
    .build();
var color2 = SpreadsheetApp.newColor()
    .setThemeColor(SpreadsheetApp.ThemeColorType.ACCENT2)
    .build();
var color3 = SpreadsheetApp.newColor()
    .setThemeColor(SpreadsheetApp.ThemeColorType.ACCENT3)
    .build();
var rule = SpreadsheetApp.newConditionalFormatRule()
    .setGradientMaxpointWithValue(color1, SpreadsheetApp.InterpolationType.NUMBER, "100")
    .setGradientMidpointWithValue(color2, SpreadsheetApp.InterpolationType.NUMBER, "50")
    .setGradientMinpointWithValue(color3, SpreadsheetApp.InterpolationType.NUMBER, "0")
    .setRanges([range])
    .build();
var rules = sheet.getConditionalFormatRules();
rules.push(rule);
sheet.setConditionalFormatRules(rules);

パラメータ

名前説明
colorColor設定する最大ポイントの色。
typeInterpolationType設定する最大ポイント補間タイプ。
valueString設定する最大値。

リターン

ConditionalFormatRuleBuilder - チェーン用のビルダー。


setGradientMaxpointWithValue(color, type, value)

条件付き書式ルールのグラデーションの maxpoint フィールドを設定します。

// Adds a conditional format rule to a sheet that causes cells in range A1:B3 to set their
// background color somewhere from red green to blue, based on their values in comparison to
// the values 0, 50, and 100.

var sheet = SpreadsheetApp.getActiveSheet();
var range = sheet.getRange("A1:B3");
var rule = SpreadsheetApp.newConditionalFormatRule()
    .setGradientMaxpointWithValue("#0000FF", SpreadsheetApp.InterpolationType.NUMBER, "100")
    .setGradientMidpointWithValue("#00FF00", SpreadsheetApp.InterpolationType.NUMBER, "50")
    .setGradientMinpointWithValue("#FF0000", SpreadsheetApp.InterpolationType.NUMBER, "0")
    .setRanges([range])
    .build();
var rules = sheet.getConditionalFormatRules();
rules.push(rule);
sheet.setConditionalFormatRules(rules);

パラメータ

名前説明
colorString設定する最大ポイントの色。
typeInterpolationType設定する最大ポイント補間タイプ。
valueString設定する最大値。

リターン

ConditionalFormatRuleBuilder - チェーン用のビルダー


setGradientMidpointObjectWithValue(color, type, value)

条件付き書式ルールのグラデーションの中点フィールドを設定します。渡された補間型が null の場合、すべての中点フィールドをクリアします。

// Adds a conditional format rule to a sheet that causes cells in range A1:B3 to set their
// background color somewhere from theme accent 1 to accent 2 to accent 3 colors, based on
// their values in comparison to the values 0, 50, and 100.

var sheet = SpreadsheetApp.getActiveSheet();
var range = sheet.getRange("A1:B3");
var color1 = SpreadsheetApp.newColor()
    .setThemeColor(SpreadsheetApp.ThemeColorType.ACCENT1)
    .build();
var color2 = SpreadsheetApp.newColor()
    .setThemeColor(SpreadsheetApp.ThemeColorType.ACCENT2)
    .build();
var color3 = SpreadsheetApp.newColor()
    .setThemeColor(SpreadsheetApp.ThemeColorType.ACCENT3)
    .build();
var rule = SpreadsheetApp.newConditionalFormatRule()
    .setGradientMaxpointWithValue(color1, SpreadsheetApp.InterpolationType.NUMBER, "100")
    .setGradientMidpointWithValue(color2, SpreadsheetApp.InterpolationType.NUMBER, "50")
    .setGradientMinpointWithValue(color3, SpreadsheetApp.InterpolationType.NUMBER, "0")
    .setRanges([range])
    .build();
var rules = sheet.getConditionalFormatRules();
rules.push(rule);
sheet.setConditionalFormatRules(rules);

パラメータ

名前説明
colorColor設定する中点の色。
typeInterpolationType設定する中点補間タイプまたはクリアする null
valueString設定する中間点の値です。

リターン

ConditionalFormatRuleBuilder - チェーン用のビルダー。


setGradientMidpointWithValue(color, type, value)

条件付き書式ルールのグラデーションの中点フィールドを設定します。渡された補間型が null の場合、すべての中点フィールドをクリアします。

// Adds a conditional format rule to a sheet that causes cells in range A1:B3 to set their
// background color somewhere from red green to blue, based on their values in comparison to
// the values 0, 50, and 100.

var sheet = SpreadsheetApp.getActiveSheet();
var range = sheet.getRange("A1:B3");
var rule = SpreadsheetApp.newConditionalFormatRule()
    .setGradientMaxpointWithValue("#0000FF", SpreadsheetApp.InterpolationType.NUMBER, "100")
    .setGradientMidpointWithValue("#00FF00", SpreadsheetApp.InterpolationType.NUMBER, "50")
    .setGradientMinpointWithValue("#FF0000", SpreadsheetApp.InterpolationType.NUMBER, "0")
    .setRanges([range])
    .build();
var rules = sheet.getConditionalFormatRules();
rules.push(rule);
sheet.setConditionalFormatRules(rules);

パラメータ

名前説明
colorString設定する中点の色。
typeInterpolationType設定する中点補間タイプまたはクリアする null
valueString設定する中間点の値です。

リターン

ConditionalFormatRuleBuilder - チェーン用のビルダー


setGradientMinpoint(color)

条件付き書式ルールのグラデーションの最小値をクリアし、ルールの範囲の最小値を使用します。また、グラデーションの最小点の色を入力色に設定します。

// Adds a conditional format rule to a sheet that causes cells in range A1:B3 to set their
// background color somewhere between white and red, based on their values in comparison to
// the ranges minimum and maximum values.

var sheet = SpreadsheetApp.getActiveSheet();
var range = sheet.getRange("A1:B3");
var rule = SpreadsheetApp.newConditionalFormatRule()
    .setGradientMaxpoint("#FF0000")
    .setGradientMinpoint("#FFFFFF")
    .setRanges([range])
    .build();
var rules = sheet.getConditionalFormatRules();
rules.push(rule);
sheet.setConditionalFormatRules(rules);

パラメータ

名前説明
colorString設定する最小点の色。

リターン

ConditionalFormatRuleBuilder - チェーン用のビルダー


setGradientMinpointObject(color)

条件付き書式ルールのグラデーションの最小値をクリアし、ルールの範囲の最小値を使用します。また、グラデーションの最小点の色を入力色に設定します。

// Adds a conditional format rule to a sheet that causes cells in range A1:B3 to set their
// background color somewhere between theme text and background colors, based on their values
// in comparison to the ranges minimum and maximum values.

var sheet = SpreadsheetApp.getActiveSheet();
var range = sheet.getRange("A1:B3");
var textColor = SpreadsheetApp.newColor()
    .setThemeColor(SpreadsheetApp.ThemeColorType.TEXT)
    .build();
var backgroundColor = SpreadsheetApp.newColor()
    .setThemeColor(SpreadsheetApp.ThemeColorType.BACKGROUND)
    .build();
var rule = SpreadsheetApp.newConditionalFormatRule()
    .setGradientMaxpoint(textColor)
    .setGradientMinpoint(backgroundColor)
    .setRanges([range])
    .build();
var rules = sheet.getConditionalFormatRules();
rules.push(rule);
sheet.setConditionalFormatRules(rules);

パラメータ

名前説明
colorColor設定する最小点の色オブジェクト。

リターン

ConditionalFormatRuleBuilder - チェーン用のビルダー。


setGradientMinpointObjectWithValue(color, type, value)

条件付き書式ルールのグラデーションの最小点フィールドを設定します。

// Adds a conditional format rule to a sheet that causes cells in range A1:B3 to set their
// background color somewhere from theme accent 1 to accent 2 to accent 3 colors, based on
// their values in comparison to the values 0, 50, and 100.

var sheet = SpreadsheetApp.getActiveSheet();
var range = sheet.getRange("A1:B3");
var color1 = SpreadsheetApp.newColor()
    .setThemeColor(SpreadsheetApp.ThemeColorType.ACCENT1)
    .build();
var color2 = SpreadsheetApp.newColor()
    .setThemeColor(SpreadsheetApp.ThemeColorType.ACCENT2)
    .build();
var color3 = SpreadsheetApp.newColor()
    .setThemeColor(SpreadsheetApp.ThemeColorType.ACCENT3)
    .build();
var rule = SpreadsheetApp.newConditionalFormatRule()
    .setGradientMaxpointWithValue(color1, SpreadsheetApp.InterpolationType.NUMBER, "100")
    .setGradientMidpointWithValue(color2, SpreadsheetApp.InterpolationType.NUMBER, "50")
    .setGradientMinpointWithValue(color3, SpreadsheetApp.InterpolationType.NUMBER, "0")
    .setRanges([range])
    .build();
var rules = sheet.getConditionalFormatRules();
rules.push(rule);
sheet.setConditionalFormatRules(rules);

パラメータ

名前説明
colorColor設定する最小点の色。
typeInterpolationType設定する最小点補間タイプ。
valueString設定する最小値。

リターン

ConditionalFormatRuleBuilder - チェーン用のビルダー。


setGradientMinpointWithValue(color, type, value)

条件付き書式ルールのグラデーションの最小点フィールドを設定します。

// Adds a conditional format rule to a sheet that causes cells in range A1:B3 to set their
// background color somewhere from red to green to blue, based on their values in comparison to
// the values 0, 50, and 100.

var sheet = SpreadsheetApp.getActiveSheet();
var range = sheet.getRange("A1:B3");
var rule = SpreadsheetApp.newConditionalFormatRule()
    .setGradientMaxpointWithValue("#0000FF", SpreadsheetApp.InterpolationType.NUMBER, "100")
    .setGradientMidpointWithValue("#00FF00", SpreadsheetApp.InterpolationType.NUMBER, "50")
    .setGradientMinpointWithValue("#FF0000", SpreadsheetApp.InterpolationType.NUMBER, "0")
    .setRanges([range])
    .build();
var rules = sheet.getConditionalFormatRules();
rules.push(rule);
sheet.setConditionalFormatRules(rules);

パラメータ

名前説明
colorString設定する最小点の色。
typeInterpolationType設定する最小点補間タイプ。
valueString設定する最小値。

リターン

ConditionalFormatRuleBuilder - チェーン用のビルダー


setItalic(italic)

条件付き書式ルールの書式にテキストを斜体に設定します。italictrue の場合、条件が満たされると、ルールはテキストを斜体にします。false の場合、条件が満たされると、ルールは既存の斜体を削除します。null を渡すと、ルールから斜体の設定が削除されます。

// Adds a conditional format rule to a sheet that causes cells in range A1:B3 to turn their
// text italic if the cell has text equal to "hello".

var sheet = SpreadsheetApp.getActiveSheet();
var range = sheet.getRange("A1:B3");
var rule = SpreadsheetApp.newConditionalFormatRule()
    .whenTextEqualTo("hello")
    .setItalic(true)
    .setRanges([range])
    .build();
var rules = sheet.getConditionalFormatRules();
rules.push(rule);
sheet.setConditionalFormatRules(rules);

パラメータ

名前説明
italicBoolean書式設定の条件が満たされた場合にテキストを斜体にするかどうか。null によりこの設定は削除されます。

リターン

ConditionalFormatRuleBuilder - チェーン用のビルダー


setRanges(ranges)

この条件付き書式ルールを適用する範囲を 1 つ以上設定します。これにより、既存の範囲がすべて置き換えられます。空の配列を設定すると、既存の範囲がすべて消去されます。ルールには少なくとも 1 つの範囲が必要です。

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

パラメータ

名前説明
rangesRange[]この条件付き書式ルールが適用される範囲。

リターン

ConditionalFormatRuleBuilder - チェーン用のビルダー


setStrikethrough(strikethrough)

条件付き書式ルールの書式に取り消し線を設定します。strikethroughtrue の場合、条件が満たされると、ルールはテキストに取り消し線を引いて、false の場合、条件が満たされると既存の取り消し線書式を削除します。null を渡すと、ルールから取り消し線の書式設定が取り除かれます。

// Adds a conditional format rule to a sheet that causes cells in range A1:B3 to strikethrough
// their text if the cell has text equal to "hello".

var sheet = SpreadsheetApp.getActiveSheet();
var range = sheet.getRange("A1:B3");
var rule = SpreadsheetApp.newConditionalFormatRule()
    .whenTextEqualTo("hello")
    .setStrikethrough(true)
    .setRanges([range])
    .build();
var rules = sheet.getConditionalFormatRules();
rules.push(rule);
sheet.setConditionalFormatRules(rules);

パラメータ

名前説明
strikethroughBoolean書式設定条件が満たされた場合にテキストに取り消し線を付けるかどうかを指定します。null の場合、この設定は削除されます。

リターン

ConditionalFormatRuleBuilder - チェーン用のビルダー


setUnderline(underline)

条件付き書式ルールの書式に下線を引くテキストを設定します。underlinetrue の場合、条件が満たされると、ルールによってテキストに下線が表示されます。false の場合、条件が満たされると既存の下線が削除されます。null を渡すと、ルールから下線の書式設定が削除されます。

// Adds a conditional format rule to a sheet that causes cells in range A1:B3 to underline
// their text if the cell has text equal to "hello".

var sheet = SpreadsheetApp.getActiveSheet();
var range = sheet.getRange("A1:B3");
var rule = SpreadsheetApp.newConditionalFormatRule()
    .whenTextEqualTo("hello")
    .setUnderline(true)
    .setRanges([range])
    .build();
var rules = sheet.getConditionalFormatRules();
rules.push(rule);
sheet.setConditionalFormatRules(rules);

パラメータ

名前説明
underlineBoolean書式設定条件が満たされた場合にテキストに下線を引くかどうかを指定します。null によりこの設定は削除されます。

リターン

ConditionalFormatRuleBuilder - チェーン用のビルダー


whenCellEmpty()

セルが空の場合にトリガーされる条件付き書式ルールを設定します。

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

リターン

ConditionalFormatRuleBuilder - チェーン用のビルダー


whenCellNotEmpty()

セルが空でない場合にトリガーされる条件付き書式ルールを設定します。

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

リターン

ConditionalFormatRuleBuilder - チェーン用のビルダー


whenDateAfter(date)

日付が指定値より後の場合にトリガーされる条件付き書式ルールを設定します。

// Adds a conditional format rule to a sheet that causes cells in range A1:B3 to turn red if
// they contain a date after 11/4/1993.

var sheet = SpreadsheetApp.getActiveSheet();
var range = sheet.getRange("A1:B3");
var rule = SpreadsheetApp.newConditionalFormatRule()
    .whenDateAfter(new Date("11/4/1993"))
    .setBackground("#FF0000")
    .setRanges([range])
    .build();
var rules = sheet.getConditionalFormatRules();
rules.push(rule);
sheet.setConditionalFormatRules(rules);

パラメータ

名前説明
dateDate最新の日付。

リターン

ConditionalFormatRuleBuilder - チェーン用のビルダー


whenDateAfter(date)

指定した相対日付より後の日付にトリガーされる条件付き書式ルールを設定します。

// Adds a conditional format rule to a sheet that causes cells in range A1:B3 to turn red if
// they contain a date after today.

var sheet = SpreadsheetApp.getActiveSheet();
var range = sheet.getRange("A1:B3");
var rule = SpreadsheetApp.newConditionalFormatRule()
    .whenDateAfter(SpreadsheetApp.RelativeDate.TODAY)
    .setBackground("#FF0000")
    .setRanges([range])
    .build();
var rules = sheet.getConditionalFormatRules();
rules.push(rule);
sheet.setConditionalFormatRules(rules);

パラメータ

名前説明
dateRelativeDate選択した日付タイプに対応する最新の日付。

リターン

ConditionalFormatRuleBuilder - チェーン用のビルダー


whenDateBefore(date)

日付が指定した日付よりも前の場合にトリガーされる条件付き書式ルールを設定します。

// Adds a conditional format rule to a sheet that causes cells in range A1:B3 to turn red if
// they contain a date before 11/4/1993.

var sheet = SpreadsheetApp.getActiveSheet();
var range = sheet.getRange("A1:B3");
var rule = SpreadsheetApp.newConditionalFormatRule()
    .whenDateBefore(new Date("11/4/1993"))
    .setBackground("#FF0000")
    .setRanges([range])
    .build();
var rules = sheet.getConditionalFormatRules();
rules.push(rule);
sheet.setConditionalFormatRules(rules);

パラメータ

名前説明
dateDate使用できない最短の日付。

リターン

ConditionalFormatRuleBuilder - チェーン用のビルダー


whenDateBefore(date)

日付が指定された相対日付よりも前の場合にトリガーされる条件付き書式ルールを設定します。

// Adds a conditional format rule to a sheet that causes cells in range A1:B3 to turn red if
// they contain a date before today.

var sheet = SpreadsheetApp.getActiveSheet();
var range = sheet.getRange("A1:B3");
var rule = SpreadsheetApp.newConditionalFormatRule()
    .whenDateBefore(SpreadsheetApp.RelativeDate.TODAY)
    .setBackground("#FF0000")
    .setRanges([range])
    .build();
var rules = sheet.getConditionalFormatRules();
rules.push(rule);
sheet.setConditionalFormatRules(rules);

パラメータ

名前説明
dateRelativeDate選択した日付タイプに対応する最新の日付。

リターン

ConditionalFormatRuleBuilder - チェーン用のビルダー


whenDateEqualTo(date)

日付が指定した日付と等しい場合にトリガーされる条件付き書式ルールを設定します。

// Adds a conditional format rule to a sheet that causes cells in range A1:B3 to turn red if
// they contain the date 11/4/1993.

var sheet = SpreadsheetApp.getActiveSheet();
var range = sheet.getRange("A1:B3");
var rule = SpreadsheetApp.newConditionalFormatRule()
    .whenDateEqualTo(new Date("11/4/1993"))
    .setBackground("#FF0000")
    .setRanges([range])
    .build();
var rules = sheet.getConditionalFormatRules();
rules.push(rule);
sheet.setConditionalFormatRules(rules);

パラメータ

名前説明
dateDate指定できる唯一の日付。

リターン

ConditionalFormatRuleBuilder - チェーン用のビルダー


whenDateEqualTo(date)

日付が指定された相対日付と等しい場合にトリガーされる条件付き書式ルールを設定します。

// Adds a conditional format rule to a sheet that causes cells in range A1:B3 to turn red if
// they contain todays date.

var sheet = SpreadsheetApp.getActiveSheet();
var range = sheet.getRange("A1:B3");
var rule = SpreadsheetApp.newConditionalFormatRule()
    .whenDateEqualTo(SpreadsheetApp.RelativeDate.TODAY)
    .setBackground("#FF0000")
    .setRanges([range])
    .build();
var rules = sheet.getConditionalFormatRules();
rules.push(rule);
sheet.setConditionalFormatRules(rules);

パラメータ

名前説明
dateRelativeDate選択した日付タイプに対応する最新の日付。

リターン

ConditionalFormatRuleBuilder - チェーン用のビルダー


whenFormulaSatisfied(formula)

指定された式が true と評価されたときにトリガーされる条件付き書式ルールを設定します。

// Adds a conditional format rule to a sheet that causes cells in range A1:B3 to turn red if
// they satisfy the condition "=EQ(B4, C3)".

var sheet = SpreadsheetApp.getActiveSheet();
var range = sheet.getRange("A1:B3");
var rule = SpreadsheetApp.newConditionalFormatRule()
    .whenFormulaSatisfied("=EQ(B4, C3)")
    .setBackground("#FF0000")
    .setRanges([range])
    .build();
var rules = sheet.getConditionalFormatRules();
rules.push(rule);
sheet.setConditionalFormatRules(rules);

パラメータ

名前説明
formulaString入力が有効な場合に true と評価されるカスタム数式。

リターン

ConditionalFormatRuleBuilder - チェーン用のビルダー


whenNumberBetween(start, end)

数値が指定された 2 つの値の間または指定された値のいずれかに該当する場合にトリガーする条件付き書式ルールを設定します。

// Adds a conditional format rule to a sheet that causes cells in range A1:B3 to turn red if
// they contain a number between 1 and 10.

var sheet = SpreadsheetApp.getActiveSheet();
var range = sheet.getRange("A1:B3");
var rule = SpreadsheetApp.newConditionalFormatRule()
    .whenNumberBetween(1, 10)
    .setBackground("#FF0000")
    .setRanges([range])
    .build();
var rules = sheet.getConditionalFormatRules();
rules.push(rule);
sheet.setConditionalFormatRules(rules);

パラメータ

名前説明
startNumber指定できる最小値。
endNumber指定できる最大値。

リターン

ConditionalFormatRuleBuilder - チェーン用のビルダー


whenNumberEqualTo(number)

数値が指定された値と等しい場合にトリガーする条件付き書式ルールを設定します。

// Adds a conditional format rule to a sheet that causes cells in range A1:B3 to turn red if
// they contain the number 10.

var sheet = SpreadsheetApp.getActiveSheet();
var range = sheet.getRange("A1:B3");
var rule = SpreadsheetApp.newConditionalFormatRule()
    .whenNumberEqualTo(10)
    .setBackground("#FF0000")
    .setRanges([range])
    .build();
var rules = sheet.getConditionalFormatRules();
rules.push(rule);
sheet.setConditionalFormatRules(rules);

パラメータ

名前説明
numberNumber唯一の許容値です。

リターン

ConditionalFormatRuleBuilder - チェーン用のビルダー


whenNumberGreaterThan(number)

数値が指定された値より大きい場合にトリガーする条件付き書式ルールを設定します。

// Adds a conditional format rule to a sheet that causes cells in range A1:B3 to turn red
// if they contain a number greater than 10.

var sheet = SpreadsheetApp.getActiveSheet();
var range = sheet.getRange("A1:B3");
var rule = SpreadsheetApp.newConditionalFormatRule()
    .whenNumberGreaterThan(10)
    .setBackground("#FF0000")
    .setRanges([range])
    .build();
var rules = sheet.getConditionalFormatRules();
rules.push(rule);
sheet.setConditionalFormatRules(rules);

パラメータ

名前説明
numberNumber許可されない最大値。

リターン

ConditionalFormatRuleBuilder - チェーン用のビルダー


whenNumberGreaterThanOrEqualTo(number)

数値が指定された値以上になったときにトリガーする条件付き書式ルールを設定します。

// Adds a conditional format rule to a sheet that causes cells in range A1:B3 to turn red if
// they contain a number greater than or equal to 10.

var sheet = SpreadsheetApp.getActiveSheet();
var range = sheet.getRange("A1:B3");
var rule = SpreadsheetApp.newConditionalFormatRule()
    .whenNumberGreaterThanOrEqualTo(10)
    .setBackground("#FF0000")
    .setRanges([range])
    .build();
var rules = sheet.getConditionalFormatRules();
rules.push(rule);
sheet.setConditionalFormatRules(rules);

パラメータ

名前説明
numberNumber指定できる最小値。

リターン

ConditionalFormatRuleBuilder - チェーン用のビルダー


whenNumberLessThan(number)

数値が指定された値より小さい場合にトリガーされる条件付き条件付き書式ルールを設定します。

// Adds a conditional format rule to a sheet that causes cells in range A1:B3 to turn red if
// they contain a number less than 10.

var sheet = SpreadsheetApp.getActiveSheet();
var range = sheet.getRange("A1:B3");
var rule = SpreadsheetApp.newConditionalFormatRule()
    .whenNumberLessThan(10)
    .setBackground("#FF0000")
    .setRanges([range])
    .build();
var rules = sheet.getConditionalFormatRules();
rules.push(rule);
sheet.setConditionalFormatRules(rules);

パラメータ

名前説明
numberNumber許可されない最小値。

リターン

ConditionalFormatRuleBuilder - チェーン用のビルダー


whenNumberLessThanOrEqualTo(number)

数値が指定された値以下の場合にトリガーされる条件付き書式ルールを設定します。

// Adds a conditional format rule to a sheet that causes cells in range A1:B3 to turn red if
// they contain a number less than or equal to 10.

var sheet = SpreadsheetApp.getActiveSheet();
var range = sheet.getRange("A1:B3");
var rule = SpreadsheetApp.newConditionalFormatRule()
    .whenNumberLessThanOrEqualTo(10)
    .setBackground("#FF0000")
    .setRanges([range])
    .build();
var rules = sheet.getConditionalFormatRules();
rules.push(rule);
sheet.setConditionalFormatRules(rules);

パラメータ

名前説明
numberNumber指定できる最大値。

リターン

ConditionalFormatRuleBuilder - チェーン用のビルダー


whenNumberNotBetween(start, end)

指定した 2 つの値の間で数値が一致しない場合にトリガーされる条件付き書式ルールを設定します。

// Adds a conditional format rule to a sheet that causes cells in range A1:B3 to turn red if
// they contain a number not between 1 and 10.

var sheet = SpreadsheetApp.getActiveSheet();
var range = sheet.getRange("A1:B3");
var rule = SpreadsheetApp.newConditionalFormatRule()
    .whenNumberNotBetween(1, 10)
    .setBackground("#FF0000")
    .setRanges([range])
    .build();
var rules = sheet.getConditionalFormatRules();
rules.push(rule);
sheet.setConditionalFormatRules(rules);

パラメータ

名前説明
startNumber許可されない最小値。
endNumber許可されない最大値。

リターン

ConditionalFormatRuleBuilder - チェーン用のビルダー


whenNumberNotEqualTo(number)

数値が指定された値と等しくない場合にトリガーされる条件付き書式ルールを設定します。

// Adds a conditional format rule to a sheet that causes cells in range A1:B3 to turn red if
// they don't contain the number 10.

var sheet = SpreadsheetApp.getActiveSheet();
var range = sheet.getRange("A1:B3");
var rule = SpreadsheetApp.newConditionalFormatRule()
    .whenNumberNotEqualTo(10)
    .setBackground("#FF0000")
    .setRanges([range])
    .build();
var rules = sheet.getConditionalFormatRules();
rules.push(rule);
sheet.setConditionalFormatRules(rules);

パラメータ

名前説明
numberNumber許可されない唯一の値。

リターン

ConditionalFormatRuleBuilder - チェーン用のビルダー


whenTextContains(text)

入力に指定値が含まれる場合にトリガーする条件付き書式ルールを設定します。

// Adds a conditional format rule to a sheet that causes cells in range A1:B3 to turn red if
// they contain the text "hello".

var sheet = SpreadsheetApp.getActiveSheet();
var range = sheet.getRange("A1:B3");
var rule = SpreadsheetApp.newConditionalFormatRule()
    .whenTextContains("hello")
    .setBackground("#FF0000")
    .setRanges([range])
    .build();
var rules = sheet.getConditionalFormatRules();
rules.push(rule);
sheet.setConditionalFormatRules(rules);

パラメータ

名前説明
textString入力に含める必要がある値。

リターン

ConditionalFormatRuleBuilder - チェーン用のビルダー


whenTextDoesNotContain(text)

入力内容に指定した値が含まれない場合にトリガーされる条件付き書式ルールを設定します。

// Adds a conditional format rule to a sheet that causes cells in range A1:B3 to turn red if
// they don't contain the text "hello".

var sheet = SpreadsheetApp.getActiveSheet();
var range = sheet.getRange("A1:B3");
var rule = SpreadsheetApp.newConditionalFormatRule()
    .whenTextDoesNotContain("hello")
    .setBackground("#FF0000")
    .setRanges([range])
    .build();
var rules = sheet.getConditionalFormatRules();
rules.push(rule);
sheet.setConditionalFormatRules(rules);

パラメータ

名前説明
textString入力に含めてはならない値。

リターン

ConditionalFormatRuleBuilder - チェーン用のビルダー


whenTextEndsWith(text)

入力が指定された値で終了したときにトリガーする条件付き書式ルールを設定します。

// Adds a conditional format rule to a sheet that causes cells in range A1:B3 to turn red if
// they end with the text "hello".

var sheet = SpreadsheetApp.getActiveSheet();
var range = sheet.getRange("A1:B3");
var rule = SpreadsheetApp.newConditionalFormatRule()
    .whenTextEndsWith("hello")
    .setBackground("#FF0000")
    .setRanges([range])
    .build();
var rules = sheet.getConditionalFormatRules();
rules.push(rule);
sheet.setConditionalFormatRules(rules);

パラメータ

名前説明
textString文字列の末尾と比較するテキスト。

リターン

ConditionalFormatRuleBuilder - チェーン用のビルダー


whenTextEqualTo(text)

入力が指定された値と等しい場合にトリガーする条件付き書式ルールを設定します。

// Adds a conditional format rule to a sheet that causes cells in range A1:B3 to turn red if
// they have text equal to "hello".

var sheet = SpreadsheetApp.getActiveSheet();
var range = sheet.getRange("A1:B3");
var rule = SpreadsheetApp.newConditionalFormatRule()
    .whenTextEqualTo("hello")
    .setBackground("#FF0000")
    .setRanges([range])
    .build();
var rules = sheet.getConditionalFormatRules();
rules.push(rule);
sheet.setConditionalFormatRules(rules);

パラメータ

名前説明
textString唯一の許容値です。

リターン

ConditionalFormatRuleBuilder - チェーン用のビルダー


whenTextStartsWith(text)

入力が指定された値で開始されたときにトリガーする条件付き書式ルールを設定します。

// Adds a conditional format rule to a sheet that causes cells in range A1:B3 to turn red if
// they start with the text "hello".

var sheet = SpreadsheetApp.getActiveSheet();
var range = sheet.getRange("A1:B3");
var rule = SpreadsheetApp.newConditionalFormatRule()
    .whenTextStartsWith("hello")
    .setBackground("#FF0000")
    .setRanges([range])
    .build();
var rules = sheet.getConditionalFormatRules();
rules.push(rule);
sheet.setConditionalFormatRules(rules);

パラメータ

名前説明
textString文字列の先頭と比較するテキスト。

リターン

ConditionalFormatRuleBuilder - チェーン用のビルダー


withCriteria(criteria, args)

BooleanCriteria 値で定義された条件に条件付き書式ルールを設定します。通常、この条件は既存のルールの criteriaarguments から取得されます。

// Adds a new conditional format rule that is a copy of the first active
// conditional format rule, except it instead sets its cells to have a black
// background color.

var sheet = SpreadsheetApp.getActiveSheet();
var rules = sheet.getConditionalFormatRules();
var booleanCondition = rules[0].getBooleanCondition();
if (booleanCondition != null) {
  var rule = SpreadsheetApp.newConditionalFormatRule()
      .withCriteria(booleanCondition.getCriteriaType(),
         booleanCondition.getCriteriaValues())
      .setBackground("#000000")
      .setRanges(rule.getRanges())
      .build();
  rules.push(rule);
}
sheet.setConditionalFormatRules(rules);

パラメータ

名前説明
criteriaBooleanCriteria条件付き書式条件のタイプ。
argsObject[]条件のタイプに適した引数の配列。引数の数とその型は、上記の when...() メソッドと同じです。

リターン

ConditionalFormatRuleBuilder - チェーン用のビルダー