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ức | Kiểu dữ liệu trả về | Mô tả ngắn |
---|---|---|
build() | ConditionalFormatRule | 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. |
copy() | ConditionalFormatRuleBuilder | 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. |
getBooleanCondition() | BooleanCondition | 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. |
getGradientCondition() | GradientCondition | 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. |
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) | ConditionalFormatRuleBuilder | 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. |
setGradientMaxpointObject(color) | ConditionalFormatRuleBuilder | 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. |
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) | ConditionalFormatRuleBuilder | 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. |
setGradientMinpointObject(color) | ConditionalFormatRuleBuilder | 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. |
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) | ConditionalFormatRuleBuilder | 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. |
whenTextStartsWith(text) | ConditionalFormatRuleBuilder | 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. |
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ừ criteria và arguments 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ên | Loại | Nội dung mô tả |
---|---|---|
color | String | Mà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ên | Loại | Nội dung mô tả |
---|---|---|
color | Color | Đố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 bold
là true
, 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ên | Loại | Nội dung mô tả |
---|---|---|
bold | Boolean | Liệ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ên | Loại | Nội dung mô tả |
---|---|---|
color | String | Mà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ên | Loại | Nội dung mô tả |
---|---|---|
color | Color | Đố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ên | Loại | Nội dung mô tả |
---|---|---|
color | String | Mà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ên | Loại | Nội dung mô tả |
---|---|---|
color | Color | Đố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ên | Loại | Nội dung mô tả |
---|---|---|
color | Color | Màu điểm tối đa cần đặt. |
type | InterpolationType | Loại nội suy điểm tối đa cần đặt. |
value | String | Giá 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ên | Loại | Nội dung mô tả |
---|---|---|
color | String | Màu điểm tối đa cần đặt. |
type | InterpolationType | Loại nội suy điểm tối đa cần đặt. |
value | String | Giá 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ên | Loại | Nội dung mô tả |
---|---|---|
color | Color | Màu điểm giữa cần đặt. |
type | InterpolationType | Loại nội suy điểm giữa cần đặt hoặc null để xoá. |
value | String | Giá 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ên | Loại | Nội dung mô tả |
---|---|---|
color | String | Màu điểm giữa cần đặt. |
type | InterpolationType | Loại nội suy điểm giữa cần đặt hoặc null để xoá. |
value | String | Giá 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ên | Loại | Nội dung mô tả |
---|---|---|
color | String | Mà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ên | Loại | Nội dung mô tả |
---|---|---|
color | Color | Đố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ên | Loại | Nội dung mô tả |
---|---|---|
color | Color | Màu điểm tối thiểu cần đặt. |
type | InterpolationType | Loại nội suy điểm nhỏ nhất cần đặt. |
value | String | Giá 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ên | Loại | Nội dung mô tả |
---|---|---|
color | String | Màu điểm tối thiểu cần đặt. |
type | InterpolationType | Loại nội suy điểm nhỏ nhất cần đặt. |
value | String | Giá 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 italic
là true
, 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ên | Loại | Nội dung mô tả |
---|---|---|
italic | Boolean | Liệ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ên | Loại | Nội dung mô tả |
---|---|---|
ranges | Range[] | 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 strikethrough
là true
, 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ên | Loại | Nội dung mô tả |
---|---|---|
strikethrough | Boolean | Liệ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 underline
là true
, 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ên | Loại | Nội dung mô tả |
---|---|---|
underline | Boolean | Liệ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ên | Loại | Nội dung mô tả |
---|---|---|
date | Date | Ngà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ên | Loại | Nội dung mô tả |
---|---|---|
date | RelativeDate | Ngà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ên | Loại | Nội dung mô tả |
---|---|---|
date | Date | Ngà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ên | Loại | Nội dung mô tả |
---|---|---|
date | RelativeDate | Ngà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ên | Loại | Nội dung mô tả |
---|---|---|
date | Date | Ngà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ên | Loại | Nội dung mô tả |
---|---|---|
date | RelativeDate | Ngà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ên | Loại | Nội dung mô tả |
---|---|---|
formula | String | Mộ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ên | Loại | Nội dung mô tả |
---|---|---|
start | Number | Giá trị thấp nhất được chấp nhận. |
end | Number | Giá 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ên | Loại | Nội dung mô tả |
---|---|---|
number | Number | Giá 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ên | Loại | Nội dung mô tả |
---|---|---|
number | Number | Giá 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ên | Loại | Nội dung mô tả |
---|---|---|
number | Number | Giá 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ên | Loại | Nội dung mô tả |
---|---|---|
number | Number | Giá 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ên | Loại | Nội dung mô tả |
---|---|---|
number | Number | Giá 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ên | Loại | Nội dung mô tả |
---|---|---|
start | Number | Giá trị thấp nhất không được chấp nhận. |
end | Number | Giá 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ên | Loại | Nội dung mô tả |
---|---|---|
number | Number | Giá 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ên | Loại | Nội dung mô tả |
---|---|---|
text | String | Giá 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ên | Loại | Nội dung mô tả |
---|---|---|
text | String | Giá 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ên | Loại | Nội dung mô tả |
---|---|---|
text | String | Vă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ên | Loại | Nội dung mô tả |
---|---|---|
text | String | Giá 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ên | Loại | Nội dung mô tả |
---|---|---|
text | String | Vă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ừ criteria
và arguments
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ên | Loại | Nội dung mô tả |
---|---|---|
criteria | BooleanCriteria | Loại tiêu chí định dạng có điều kiện. |
args | Object[] | 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