Class ConditionalFormatRuleBuilder

ConditionalFormatRuleBuilder

Trình tạo quy tắc định dạng có điều kiện.

// 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);

Phương thức

Phương thứcKiểu dữ liệu trả vềMô tả ngắn
build()ConditionalFormatRuleTạo quy tắc định dạng có điều kiện từ chế độ cài đặt áp dụng cho trình tạo.
copy()ConditionalFormatRuleBuilderTrả về giá trị đặt trước của trình tạo quy tắc có chế độ cài đặt của quy tắc này.
getBooleanCondition()BooleanConditionTruy xuất thông tin BooleanCondition của quy tắc nếu quy tắc này sử dụng các tiêu chí điều kiện boolean.
getGradientCondition()GradientConditionTruy xuất thông tin GradientCondition của quy tắc nếu quy tắc này sử dụng tiêu chí điều kiện chuyển màu.
getRanges()Range[]Truy xuất các dải ô được áp dụng quy tắc định dạng có điều kiện này.
setBackground(color)ConditionalFormatRuleBuilderĐặt màu nền cho định dạng của quy tắc định dạng có điều kiện.
setBackgroundObject(color)ConditionalFormatRuleBuilderĐặt màu nền cho định dạng của quy tắc định dạng có điều kiện.
setBold(bold)ConditionalFormatRuleBuilderĐặt kiểu in đậm văn bản cho định dạng của quy tắc định dạng có điều kiện.
setFontColor(color)ConditionalFormatRuleBuilderĐặt màu phông chữ cho định dạng của quy tắc định dạng có điều kiện.
setFontColorObject(color)ConditionalFormatRuleBuilderĐặt màu phông chữ cho định dạng của quy tắc định dạng có điều kiện.
setGradientMaxpoint(color)ConditionalFormatRuleBuilderXoá giá trị điểm tối đa chuyển màu của quy tắc định dạng có điều kiện và thay vào đó sử dụng giá trị tối đa trong phạm vi của quy tắc.
setGradientMaxpointObject(color)ConditionalFormatRuleBuilderXoá giá trị điểm tối đa chuyển màu của quy tắc định dạng có điều kiện và thay vào đó sử dụng giá trị tối đa trong phạm vi của quy tắc.
setGradientMaxpointObjectWithValue(color, type, value)ConditionalFormatRuleBuilderĐặt các trường điểm tối đa chuyển màu của quy tắc định dạng có điều kiện.
setGradientMaxpointWithValue(color, type, value)ConditionalFormatRuleBuilderĐặt các trường điểm tối đa chuyển màu của quy tắc định dạng có điều kiện.
setGradientMidpointObjectWithValue(color, type, value)ConditionalFormatRuleBuilderĐặt các trường điểm giữa chuyển màu của quy tắc định dạng có điều kiện.
setGradientMidpointWithValue(color, type, value)ConditionalFormatRuleBuilderĐặt các trường điểm giữa chuyển màu của quy tắc định dạng có điều kiện.
setGradientMinpoint(color)ConditionalFormatRuleBuilderXoá giá trị điểm tối thiểu chuyển màu của quy tắc định dạng có điều kiện và thay vào đó sử dụng giá trị tối thiểu trong phạm vi của quy tắc.
setGradientMinpointObject(color)ConditionalFormatRuleBuilderXoá giá trị điểm tối thiểu chuyển màu của quy tắc định dạng có điều kiện và thay vào đó sử dụng giá trị tối thiểu trong phạm vi của quy tắc.
setGradientMinpointObjectWithValue(color, type, value)ConditionalFormatRuleBuilderĐặt các trường điểm nhỏ chuyển màu của quy tắc định dạng có điều kiện.
setGradientMinpointWithValue(color, type, value)ConditionalFormatRuleBuilderĐặt các trường điểm nhỏ chuyển màu của quy tắc định dạng có điều kiện.
setItalic(italic)ConditionalFormatRuleBuilderĐặt chữ in nghiêng cho định dạng của quy tắc định dạng có điều kiện.
setRanges(ranges)ConditionalFormatRuleBuilderĐặt một hoặc nhiều dải ô để áp dụng quy tắc định dạng có điều kiện này.
setStrikethrough(strikethrough)ConditionalFormatRuleBuilderĐặt gạch ngang văn bản cho định dạng của quy tắc định dạng có điều kiện.
setUnderline(underline)ConditionalFormatRuleBuilderĐặt văn bản gạch dưới cho định dạng của quy tắc định dạng có điều kiện.
whenCellEmpty()ConditionalFormatRuleBuilderĐặt quy tắc định dạng có điều kiện để kích hoạt khi ô trống.
whenCellNotEmpty()ConditionalFormatRuleBuilderĐặt quy tắc định dạng có điều kiện để kích hoạt khi ô không trống.
whenDateAfter(date)ConditionalFormatRuleBuilderĐặt quy tắc định dạng có điều kiện để kích hoạt khi một ngày sau giá trị đã cho.
whenDateAfter(date)ConditionalFormatRuleBuilderĐặt quy tắc định dạng có điều kiện để kích hoạt khi một ngày sau ngày tương đối đã cho.
whenDateBefore(date)ConditionalFormatRuleBuilderĐặt quy tắc định dạng có điều kiện để kích hoạt khi một ngày trước ngày đã chọn.
whenDateBefore(date)ConditionalFormatRuleBuilderĐặt quy tắc định dạng có điều kiện để kích hoạt khi một ngày trước ngày tương đối đã chọn.
whenDateEqualTo(date)ConditionalFormatRuleBuilderĐặt quy tắc định dạng có điều kiện để kích hoạt khi ngày bằng với ngày đã chọn.
whenDateEqualTo(date)ConditionalFormatRuleBuilderĐặt quy tắc định dạng có điều kiện để kích hoạt khi ngày bằng với ngày tương đối đã cho.
whenFormulaSatisfied(formula)ConditionalFormatRuleBuilderĐặt quy tắc định dạng có điều kiện để kích hoạt khi công thức cho trước có giá trị true.
whenNumberBetween(start, end)ConditionalFormatRuleBuilderĐặt quy tắc định dạng có điều kiện để kích hoạt khi một số nằm giữa hoặc là một trong hai giá trị được chỉ định.
whenNumberEqualTo(number)ConditionalFormatRuleBuilderĐặt quy tắc định dạng có điều kiện để kích hoạt khi một số bằng với giá trị đã cho.
whenNumberGreaterThan(number)ConditionalFormatRuleBuilderĐặt quy tắc định dạng có điều kiện để kích hoạt khi một số lớn hơn giá trị đã cho.
whenNumberGreaterThanOrEqualTo(number)ConditionalFormatRuleBuilderĐặt quy tắc định dạng có điều kiện để kích hoạt khi một số lớn hơn hoặc bằng giá trị đã cho.
whenNumberLessThan(number)ConditionalFormatRuleBuilderĐặt quy tắc định dạng có điều kiện để kích hoạt khi một số nhỏ hơn giá trị đã cho.
whenNumberLessThanOrEqualTo(number)ConditionalFormatRuleBuilderĐặt quy tắc định dạng có điều kiện để kích hoạt khi một số nhỏ hơn hoặc bằng giá trị đã cho.
whenNumberNotBetween(start, end)ConditionalFormatRuleBuilderĐặt quy tắc định dạng có điều kiện để kích hoạt khi một số không nằm trong khoảng và không nằm trong hai giá trị được chỉ định.
whenNumberNotEqualTo(number)ConditionalFormatRuleBuilderĐặt quy tắc định dạng có điều kiện để kích hoạt khi một số không bằng giá trị đã cho.
whenTextContains(text)ConditionalFormatRuleBuilderĐặt quy tắc định dạng có điều kiện để kích hoạt khi giá trị nhập chứa giá trị đã cho.
whenTextDoesNotContain(text)ConditionalFormatRuleBuilderĐặt quy tắc định dạng có điều kiện để kích hoạt khi dữ liệu đầu vào không chứa giá trị đã cho.
whenTextEndsWith(text)ConditionalFormatRuleBuilderĐặt quy tắc định dạng có điều kiện để kích hoạt khi giá trị nhập kết thúc bằng giá trị đã cho.
whenTextEqualTo(text)ConditionalFormatRuleBuilderThiết lập quy tắc định dạng có điều kiện để kích hoạt khi giá trị nhập vào bằng giá trị đã cho.
whenTextStartsWith(text)ConditionalFormatRuleBuilderThiết lập quy tắc định dạng có điều kiện để kích hoạt khi giá trị nhập bắt đầu bằng giá trị đã cho.
withCriteria(criteria, args)ConditionalFormatRuleBuilderĐặt quy tắc định dạng có điều kiện thành tiêu chí được xác định bởi các giá trị BooleanCriteria, thường được lấy từ criteriaarguments của một quy tắc hiện có.

Tài liệu chi tiết

build()

Tạo quy tắc định dạng có điều kiện từ chế độ cài đặt áp dụng cho trình tạo.

Cầu thủ trả bóng

ConditionalFormatRule — thể hiện quy tắc định dạng có điều kiện


copy()

Trả về giá trị đặt trước của trình tạo quy tắc có chế độ cài đặt của quy tắc này.

Cầu thủ trả bóng

ConditionalFormatRuleBuilder — một trình tạo dựa trên tùy chọn cài đặt của quy tắc này


getBooleanCondition()

Truy xuất thông tin BooleanCondition của quy tắc nếu quy tắc này sử dụng các tiêu chí điều kiện boolean. Nếu không, hãy trả về 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());
}

Cầu thủ trả bóng

BooleanCondition – đối tượng điều kiện boolean hoặc null nếu quy tắc không sử dụng điều kiện boolean.


getGradientCondition()

Truy xuất thông tin GradientCondition của quy tắc nếu quy tắc này sử dụng tiêu chí điều kiện chuyển màu. Nếu không, hãy trả về 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());
}

Cầu thủ trả bóng

GradientCondition – Đối tượng điều kiện chuyển màu hoặc null nếu quy tắc không sử dụng điều kiện chuyển màu.


getRanges()

Truy xuất các dải ô được áp dụng quy tắc định dạng có điều kiện này.

// 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());
}

Cầu thủ trả bóng

Range[] — các dải ô được áp dụng quy tắc định dạng có điều kiện này.


setBackground(color)

Đặt màu nền cho định dạng của quy tắc định dạng có điều kiện. Việc truyền vào null sẽ xoá chế độ cài đặt định dạng màu nền khỏi quy tắc.

// 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);

Các tham số

TênLoạiNội dung mô tả
colorStringMàu mong muốn hoặc null để xoá.

Cầu thủ trả bóng

ConditionalFormatRuleBuilder – trình tạo để tạo chuỗi


setBackgroundObject(color)

Đặt màu nền cho định dạng của quy tắc định dạng có điều kiện. Việc truyền vào null sẽ xoá chế độ cài đặt định dạng màu nền khỏi quy tắc.

// 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);

Các tham số

TênLoạiNội dung mô tả
colorColorĐối tượng màu mong muốn hoặc null để xoá.

Cầu thủ trả bóng

ConditionalFormatRuleBuilder – Trình tạo để tạo chuỗi.


setBold(bold)

Đặt kiểu in đậm văn bản cho định dạng của quy tắc định dạng có điều kiện. Nếu boldtrue, quy tắc sẽ in đậm văn bản nếu điều kiện được đáp ứng; nếu false, quy tắc này sẽ xoá mọi kiểu in đậm hiện có nếu điều kiện được đáp ứng. Việc truyền vào null sẽ xoá chế độ cài đặt định dạng in đậm khỏi quy tắc.

// 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);

Các tham số

TênLoạiNội dung mô tả
boldBooleanLiệu văn bản có được in đậm hay không nếu đáp ứng điều kiện định dạng; null sẽ xoá chế độ cài đặt này.

Cầu thủ trả bóng

ConditionalFormatRuleBuilder – trình tạo để tạo chuỗi


setFontColor(color)

Đặt màu phông chữ cho định dạng của quy tắc định dạng có điều kiện. Việc truyền vào null sẽ xoá chế độ cài đặt định dạng màu phông chữ khỏi quy tắc.

// 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);

Các tham số

TênLoạiNội dung mô tả
colorStringMàu mong muốn hoặc null để xoá.

Cầu thủ trả bóng

ConditionalFormatRuleBuilder – trình tạo để tạo chuỗi


setFontColorObject(color)

Đặt màu phông chữ cho định dạng của quy tắc định dạng có điều kiện. Việc truyền vào null sẽ xoá chế độ cài đặt định dạng màu phông chữ khỏi quy tắc.

// 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);

Các tham số

TênLoạiNội dung mô tả
colorColorĐối tượng màu mong muốn hoặc null để xoá.

Cầu thủ trả bóng

ConditionalFormatRuleBuilder – Trình tạo để tạo chuỗi.


setGradientMaxpoint(color)

Xoá giá trị điểm tối đa chuyển màu của quy tắc định dạng có điều kiện và thay vào đó sử dụng giá trị tối đa trong phạm vi của quy tắc. Đồng thời đặt màu điểm cực đại của hiệu ứng chuyển màu thành màu đầu vào.

// 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);

Các tham số

TênLoạiNội dung mô tả
colorStringMàu điểm tối đa cần đặt.

Cầu thủ trả bóng

ConditionalFormatRuleBuilder – trình tạo để tạo chuỗi


setGradientMaxpointObject(color)

Xoá giá trị điểm tối đa chuyển màu của quy tắc định dạng có điều kiện và thay vào đó sử dụng giá trị tối đa trong phạm vi của quy tắc. Đồng thời đặt màu điểm cực đại của hiệu ứng chuyển màu thành màu đầu vào.

// 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);

Các tham số

TênLoạiNội dung mô tả
colorColorĐối tượng màu maxpoint cần đặt.

Cầu thủ trả bóng

ConditionalFormatRuleBuilder – Trình tạo để tạo chuỗi.


setGradientMaxpointObjectWithValue(color, type, value)

Đặt các trường điểm tối đa chuyển màu của quy tắc định dạng có điều kiện.

// 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);

Các tham số

TênLoạiNội dung mô tả
colorColorMàu điểm tối đa cần đặt.
typeInterpolationTypeLoại nội suy điểm tối đa cần đặt.
valueStringGiá trị điểm tối đa cần đặt.

Cầu thủ trả bóng

ConditionalFormatRuleBuilder – Trình tạo để tạo chuỗi.


setGradientMaxpointWithValue(color, type, value)

Đặt các trường điểm tối đa chuyển màu của quy tắc định dạng có điều kiện.

// 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);

Các tham số

TênLoạiNội dung mô tả
colorStringMàu điểm tối đa cần đặt.
typeInterpolationTypeLoại nội suy điểm tối đa cần đặt.
valueStringGiá trị điểm tối đa cần đặt.

Cầu thủ trả bóng

ConditionalFormatRuleBuilder – trình tạo để tạo chuỗi


setGradientMidpointObjectWithValue(color, type, value)

Đặt các trường điểm giữa chuyển màu của quy tắc định dạng có điều kiện. Xoá tất cả các trường điểm giữa nếu loại nội suy đã truyền là 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);

Các tham số

TênLoạiNội dung mô tả
colorColorMàu điểm giữa cần đặt.
typeInterpolationTypeLoại nội suy điểm giữa cần đặt hoặc null để xoá.
valueStringGiá trị điểm giữa cần đặt.

Cầu thủ trả bóng

ConditionalFormatRuleBuilder – Trình tạo để tạo chuỗi.


setGradientMidpointWithValue(color, type, value)

Đặt các trường điểm giữa chuyển màu của quy tắc định dạng có điều kiện. Xoá tất cả các trường điểm giữa nếu loại nội suy đã truyền là 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);

Các tham số

TênLoạiNội dung mô tả
colorStringMàu điểm giữa cần đặt.
typeInterpolationTypeLoại nội suy điểm giữa cần đặt hoặc null để xoá.
valueStringGiá trị điểm giữa cần đặt.

Cầu thủ trả bóng

ConditionalFormatRuleBuilder – trình tạo để tạo chuỗi


setGradientMinpoint(color)

Xoá giá trị điểm tối thiểu chuyển màu của quy tắc định dạng có điều kiện và thay vào đó sử dụng giá trị tối thiểu trong phạm vi của quy tắc. Đồng thời đặt màu điểm tối thiểu của hiệu ứng chuyển màu thành màu đầu vào.

// 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);

Các tham số

TênLoạiNội dung mô tả
colorStringMàu điểm tối thiểu cần đặt.

Cầu thủ trả bóng

ConditionalFormatRuleBuilder – trình tạo để tạo chuỗi


setGradientMinpointObject(color)

Xoá giá trị điểm tối thiểu chuyển màu của quy tắc định dạng có điều kiện và thay vào đó sử dụng giá trị tối thiểu trong phạm vi của quy tắc. Đồng thời đặt màu điểm tối thiểu của hiệu ứng chuyển màu thành màu đầu vào.

// 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);

Các tham số

TênLoạiNội dung mô tả
colorColorĐối tượng màu minpoint cần đặt.

Cầu thủ trả bóng

ConditionalFormatRuleBuilder – Trình tạo để tạo chuỗi.


setGradientMinpointObjectWithValue(color, type, value)

Đặt các trường điểm nhỏ chuyển màu của quy tắc định dạng có điều kiện.

// 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);

Các tham số

TênLoạiNội dung mô tả
colorColorMàu điểm tối thiểu cần đặt.
typeInterpolationTypeLoại nội suy điểm nhỏ nhất cần đặt.
valueStringGiá trị điểm tối thiểu cần đặt.

Cầu thủ trả bóng

ConditionalFormatRuleBuilder – Trình tạo để tạo chuỗi.


setGradientMinpointWithValue(color, type, value)

Đặt các trường điểm nhỏ chuyển màu của quy tắc định dạng có điều kiện.

// 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);

Các tham số

TênLoạiNội dung mô tả
colorStringMàu điểm tối thiểu cần đặt.
typeInterpolationTypeLoại nội suy điểm nhỏ nhất cần đặt.
valueStringGiá trị điểm tối thiểu cần đặt.

Cầu thủ trả bóng

ConditionalFormatRuleBuilder – trình tạo để tạo chuỗi


setItalic(italic)

Đặt chữ in nghiêng cho định dạng của quy tắc định dạng có điều kiện. Nếu italictrue, quy tắc này sẽ in nghiêng văn bản nếu đáp ứng điều kiện; nếu false, quy tắc này sẽ xoá mọi kiểu in nghiêng hiện có nếu đáp ứng điều kiện. Việc truyền null vào sẽ xoá chế độ cài đặt định dạng in nghiêng khỏi quy tắc.

// 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);

Các tham số

TênLoạiNội dung mô tả
italicBooleanLiệu văn bản có nên được in nghiêng nếu đáp ứng điều kiện định dạng hay không; null sẽ xoá chế độ cài đặt này.

Cầu thủ trả bóng

ConditionalFormatRuleBuilder – trình tạo để tạo chuỗi


setRanges(ranges)

Đặt một hoặc nhiều dải ô để áp dụng quy tắc định dạng có điều kiện này. Thao tác này sẽ thay thế mọi dải ô hiện có. Thao tác đặt một mảng trống sẽ xoá mọi dải ô hiện có. Mỗi quy tắc phải có ít nhất một phạm vi.

// 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);

Các tham số

TênLoạiNội dung mô tả
rangesRange[]Các phạm vi áp dụng quy tắc định dạng có điều kiện này.

Cầu thủ trả bóng

ConditionalFormatRuleBuilder – trình tạo để tạo chuỗi


setStrikethrough(strikethrough)

Đặt gạch ngang văn bản cho định dạng của quy tắc định dạng có điều kiện. Nếu strikethroughtrue, thì văn bản sẽ bị gạch ngang do quy tắc nếu đáp ứng điều kiện; nếu false, quy tắc sẽ xoá mọi định dạng bị gạch ngang hiện có nếu đáp ứng điều kiện. Thao tác truyền vào null sẽ xoá chế độ cài đặt định dạng gạch ngang khỏi quy tắc.

// 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);

Các tham số

TênLoạiNội dung mô tả
strikethroughBooleanLiệu văn bản có nên bị gạch ngang hay không nếu đáp ứng điều kiện định dạng; null sẽ xoá chế độ cài đặt này.

Cầu thủ trả bóng

ConditionalFormatRuleBuilder – trình tạo để tạo chuỗi


setUnderline(underline)

Đặt văn bản gạch dưới cho định dạng của quy tắc định dạng có điều kiện. Nếu underlinetrue, quy tắc sẽ gạch chân văn bản nếu đáp ứng điều kiện; nếu false, quy tắc này sẽ xoá mọi dấu gạch dưới hiện có nếu đáp ứng điều kiện đó. Việc truyền null vào sẽ xoá chế độ cài đặt định dạng gạch chân khỏi quy tắc.

// 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);

Các tham số

TênLoạiNội dung mô tả
underlineBooleanLiệu văn bản có nên được gạch chân hay không nếu đáp ứng điều kiện định dạng; null sẽ xóa chế độ cài đặt này.

Cầu thủ trả bóng

ConditionalFormatRuleBuilder – trình tạo để tạo chuỗi


whenCellEmpty()

Đặt quy tắc định dạng có điều kiện để kích hoạt khi ô trống.

// 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);

Cầu thủ trả bóng

ConditionalFormatRuleBuilder – trình tạo để tạo chuỗi


whenCellNotEmpty()

Đặt quy tắc định dạng có điều kiện để kích hoạt khi ô không trống.

// 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);

Cầu thủ trả bóng

ConditionalFormatRuleBuilder – trình tạo để tạo chuỗi


whenDateAfter(date)

Đặt quy tắc định dạng có điều kiện để kích hoạt khi một ngày sau giá trị đã cho.

// 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);

Các tham số

TênLoạiNội dung mô tả
dateDateNgày gần đây nhất.

Cầu thủ trả bóng

ConditionalFormatRuleBuilder – trình tạo để tạo chuỗi


whenDateAfter(date)

Đặt quy tắc định dạng có điều kiện để kích hoạt khi một ngày sau ngày tương đối đã cho.

// 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);

Các tham số

TênLoạiNội dung mô tả
dateRelativeDateNgày gần nhất so với loại ngày đã chọn.

Cầu thủ trả bóng

ConditionalFormatRuleBuilder – trình tạo để tạo chuỗi


whenDateBefore(date)

Đặt quy tắc định dạng có điều kiện để kích hoạt khi một ngày trước ngày đã chọn.

// 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);

Các tham số

TênLoạiNội dung mô tả
dateDateNgày sớm nhất không được chấp nhận.

Cầu thủ trả bóng

ConditionalFormatRuleBuilder – trình tạo để tạo chuỗi


whenDateBefore(date)

Đặt quy tắc định dạng có điều kiện để kích hoạt khi một ngày trước ngày tương đối đã chọn.

// 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);

Các tham số

TênLoạiNội dung mô tả
dateRelativeDateNgày gần nhất so với loại ngày đã chọn.

Cầu thủ trả bóng

ConditionalFormatRuleBuilder – trình tạo để tạo chuỗi


whenDateEqualTo(date)

Đặt quy tắc định dạng có điều kiện để kích hoạt khi ngày bằng với ngày đã chọn.

// 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);

Các tham số

TênLoạiNội dung mô tả
dateDateNgày duy nhất được chấp nhận.

Cầu thủ trả bóng

ConditionalFormatRuleBuilder – trình tạo để tạo chuỗi


whenDateEqualTo(date)

Đặt quy tắc định dạng có điều kiện để kích hoạt khi ngày bằng với ngày tương đối đã cho.

// 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);

Các tham số

TênLoạiNội dung mô tả
dateRelativeDateNgày gần nhất so với loại ngày đã chọn.

Cầu thủ trả bóng

ConditionalFormatRuleBuilder – trình tạo để tạo chuỗi


whenFormulaSatisfied(formula)

Đặt quy tắc định dạng có điều kiện để kích hoạt khi công thức cho trước có giá trị 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);

Các tham số

TênLoạiNội dung mô tả
formulaStringMột công thức tuỳ chỉnh đánh giá là true nếu giá trị nhập vào là hợp lệ.

Cầu thủ trả bóng

ConditionalFormatRuleBuilder – trình tạo để tạo chuỗi


whenNumberBetween(start, end)

Đặt quy tắc định dạng có điều kiện để kích hoạt khi một số nằm giữa hoặc là một trong hai giá trị được chỉ định.

// 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);

Các tham số

TênLoạiNội dung mô tả
startNumberGiá trị thấp nhất được chấp nhận.
endNumberGiá trị cao nhất được chấp nhận.

Cầu thủ trả bóng

ConditionalFormatRuleBuilder – trình tạo để tạo chuỗi


whenNumberEqualTo(number)

Đặt quy tắc định dạng có điều kiện để kích hoạt khi một số bằng với giá trị đã cho.

// 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);

Các tham số

TênLoạiNội dung mô tả
numberNumberGiá trị duy nhất được chấp nhận.

Cầu thủ trả bóng

ConditionalFormatRuleBuilder – trình tạo để tạo chuỗi


whenNumberGreaterThan(number)

Đặt quy tắc định dạng có điều kiện để kích hoạt khi một số lớn hơn giá trị đã cho.

// 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);

Các tham số

TênLoạiNội dung mô tả
numberNumberGiá trị cao nhất không được chấp nhận.

Cầu thủ trả bóng

ConditionalFormatRuleBuilder – trình tạo để tạo chuỗi


whenNumberGreaterThanOrEqualTo(number)

Đặt quy tắc định dạng có điều kiện để kích hoạt khi một số lớn hơn hoặc bằng giá trị đã cho.

// 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);

Các tham số

TênLoạiNội dung mô tả
numberNumberGiá trị thấp nhất được chấp nhận.

Cầu thủ trả bóng

ConditionalFormatRuleBuilder – trình tạo để tạo chuỗi


whenNumberLessThan(number)

Đặt quy tắc định dạng có điều kiện để kích hoạt khi một số nhỏ hơn giá trị đã cho.

// 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);

Các tham số

TênLoạiNội dung mô tả
numberNumberGiá trị thấp nhất không được chấp nhận.

Cầu thủ trả bóng

ConditionalFormatRuleBuilder – trình tạo để tạo chuỗi


whenNumberLessThanOrEqualTo(number)

Đặt quy tắc định dạng có điều kiện để kích hoạt khi một số nhỏ hơn hoặc bằng giá trị đã cho.

// 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);

Các tham số

TênLoạiNội dung mô tả
numberNumberGiá trị cao nhất được chấp nhận.

Cầu thủ trả bóng

ConditionalFormatRuleBuilder – trình tạo để tạo chuỗi


whenNumberNotBetween(start, end)

Đặt quy tắc định dạng có điều kiện để kích hoạt khi một số không nằm trong khoảng và không nằm trong hai giá trị được chỉ định.

// 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);

Các tham số

TênLoạiNội dung mô tả
startNumberGiá trị thấp nhất không được chấp nhận.
endNumberGiá trị cao nhất không được chấp nhận.

Cầu thủ trả bóng

ConditionalFormatRuleBuilder – trình tạo để tạo chuỗi


whenNumberNotEqualTo(number)

Đặt quy tắc định dạng có điều kiện để kích hoạt khi một số không bằng giá trị đã cho.

// 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);

Các tham số

TênLoạiNội dung mô tả
numberNumberGiá trị duy nhất không được chấp nhận.

Cầu thủ trả bóng

ConditionalFormatRuleBuilder – trình tạo để tạo chuỗi


whenTextContains(text)

Đặt quy tắc định dạng có điều kiện để kích hoạt khi giá trị nhập chứa giá trị đã cho.

// 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);

Các tham số

TênLoạiNội dung mô tả
textStringGiá trị mà giá trị nhập phải chứa.

Cầu thủ trả bóng

ConditionalFormatRuleBuilder – trình tạo để tạo chuỗi


whenTextDoesNotContain(text)

Đặt quy tắc định dạng có điều kiện để kích hoạt khi dữ liệu đầu vào không chứa giá trị đã cho.

// 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);

Các tham số

TênLoạiNội dung mô tả
textStringGiá trị mà giá trị nhập không được chứa.

Cầu thủ trả bóng

ConditionalFormatRuleBuilder – trình tạo để tạo chuỗi


whenTextEndsWith(text)

Đặt quy tắc định dạng có điều kiện để kích hoạt khi giá trị nhập kết thúc bằng giá trị đã cho.

// 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);

Các tham số

TênLoạiNội dung mô tả
textStringVăn bản cần so sánh với cuối chuỗi.

Cầu thủ trả bóng

ConditionalFormatRuleBuilder – trình tạo để tạo chuỗi


whenTextEqualTo(text)

Thiết lập quy tắc định dạng có điều kiện để kích hoạt khi giá trị nhập vào bằng giá trị đã cho.

// 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);

Các tham số

TênLoạiNội dung mô tả
textStringGiá trị duy nhất được chấp nhận.

Cầu thủ trả bóng

ConditionalFormatRuleBuilder – trình tạo để tạo chuỗi


whenTextStartsWith(text)

Thiết lập quy tắc định dạng có điều kiện để kích hoạt khi giá trị nhập bắt đầu bằng giá trị đã cho.

// 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);

Các tham số

TênLoạiNội dung mô tả
textStringVăn bản cần so sánh với đầu chuỗi.

Cầu thủ trả bóng

ConditionalFormatRuleBuilder – trình tạo để tạo chuỗi


withCriteria(criteria, args)

Đặt quy tắc định dạng có điều kiện thành tiêu chí được xác định bởi các giá trị BooleanCriteria, thường được lấy từ criteriaarguments của một quy tắc hiện có.

// 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);

Các tham số

TênLoạiNội dung mô tả
criteriaBooleanCriteriaLoại tiêu chí định dạng có điều kiện.
argsObject[]Một mảng các đối số phù hợp với loại tiêu chí; số lượng đối số và loại của các đối số đó khớp với phương thức when...() tương ứng ở trên.

Cầu thủ trả bóng

ConditionalFormatRuleBuilder – trình tạo để tạo chuỗi