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. const sheet = SpreadsheetApp.getActiveSheet(); const range = sheet.getRange('A1:B3'); const rule = SpreadsheetApp.newConditionalFormatRule() .whenNumberBetween(1, 10) .setBackground('#FF0000') .setRanges([range]) .build(); const rules = sheet.getConditionalFormatRules(); rules.push(rule); sheet.setConditionalFormatRules(rules);
Phương thức
Phương thức | Kiểu dữ liệu trả về | Mô tả ngắn |
---|---|---|
build() | Conditional | Tạo một quy tắc định dạng có điều kiện từ các chế độ cài đặt được áp dụng cho trình tạo. |
copy() | Conditional | Trả về một chế độ đặt sẵn của trình tạo quy tắc với các chế độ cài đặt của quy tắc này. |
get | Boolean | Truy xuất thông tin Boolean của quy tắc nếu quy tắc này sử dụng tiêu chí điều kiện boolean. |
get | Gradient | Truy xuất thông tin Gradient 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. |
get | Range[] | Truy xuất các dải ô mà quy tắc định dạng có điều kiện này được áp dụng. |
set | Conditional | Đặt màu nền cho định dạng của quy tắc định dạng có điều kiện. |
set | Conditional | Đặt màu nền cho định dạng của quy tắc định dạng có điều kiện. |
set | Conditional | Đặt chế độ in đậm văn bản cho định dạng của quy tắc định dạng có điều kiện. |
set | Conditional | Đặt màu phông chữ cho định dạng của quy tắc định dạng có điều kiện. |
set | Conditional | Đặt màu phông chữ cho định dạng của quy tắc định dạng có điều kiện. |
set | Conditional | Xoá giá trị điểm tối đa của dải màu trong quy tắc định dạng có điều kiện và thay vào đó, sử dụng giá trị tối đa trong các dải của quy tắc. |
set | Conditional | Xoá giá trị điểm tối đa của dải màu trong quy tắc định dạng có điều kiện và thay vào đó, sử dụng giá trị tối đa trong các dải của quy tắc. |
set | Conditional | Đặt các trường điểm tối đa của dải màu trong quy tắc định dạng có điều kiện. |
set | Conditional | Đặt các trường điểm tối đa của dải màu trong quy tắc định dạng có điều kiện. |
set | Conditional | Đặt các trường trung điểm của dải màu trong quy tắc định dạng có điều kiện. |
set | Conditional | Đặt các trường trung điểm của dải màu trong quy tắc định dạng có điều kiện. |
set | Conditional | Xoá giá trị điểm tối thiểu của dải màu trong 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 các dải của quy tắc. |
set | Conditional | Xoá giá trị điểm tối thiểu của dải màu trong 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 các dải của quy tắc. |
set | Conditional | Đặt các trường minpoint của dải màu trong quy tắc định dạng có điều kiện. |
set | Conditional | Đặt các trường minpoint của dải màu trong quy tắc định dạng có điều kiện. |
set | Conditional | Đặt văn bản in nghiêng cho định dạng của quy tắc định dạng có điều kiện. |
set | Conditional | Đặt một hoặc nhiều dải ô mà quy tắc định dạng có điều kiện này được áp dụng. |
set | Conditional | Đặt hiệu ứng gạch ngang cho văn bản trong định dạng của quy tắc định dạng có điều kiện. |
set | Conditional | Đặt chế độ gạch chân văn bản cho định dạng của quy tắc định dạng có điều kiện. |
when | Conditional | Đặt quy tắc định dạng có điều kiện để kích hoạt khi ô trống. |
when | Conditional | Đặt quy tắc định dạng có điều kiện để kích hoạt khi ô không trống. |
when | Conditional | Đặt quy tắc định dạng có điều kiện để kích hoạt khi ngày sau giá trị đã cho. |
when | Conditional | Đặt quy tắc định dạng có điều kiện để kích hoạt khi ngày sau ngày tương đối đã cho. |
when | Conditional | Đặ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 đã cho. |
when | Conditional | Đặt quy tắc định dạng có điều kiện để kích hoạt khi ngày trước ngày tương đối đã cho. |
when | Conditional | Đặ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 đã cho. |
when | Conditional | Đặ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. |
when | Conditional | Đặt quy tắc định dạng có điều kiện để kích hoạt khi công thức đã cho đánh giá thành true . |
when | Conditional | Đặt quy tắc định dạng có điều kiện để kích hoạt khi một số nằm trong khoảng hoặc là một trong hai giá trị được chỉ định. |
when | Conditional | Đặ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. |
when | Conditional | Đặ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. |
when | Conditional | Đặ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. |
when | Conditional | Đặ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. |
when | Conditional | Đặ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. |
when | Conditional | Đặ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 phải là một trong hai giá trị được chỉ định. |
when | Conditional | Đặt quy tắc định dạng có điều kiện để kích hoạt khi một số không bằng với giá trị đã cho. |
when | Conditional | Đặt quy tắc định dạng có điều kiện để kích hoạt khi dữ liệu đầu vào chứa giá trị đã cho. |
when | Conditional | Đặ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. |
when | Conditional | Đặt quy tắc định dạng có điều kiện để kích hoạt khi dữ liệu đầu vào kết thúc bằng giá trị đã cho. |
when | Conditional | Đặt quy tắc định dạng có điều kiện để kích hoạt khi dữ liệu đầu vào bằng với giá trị đã cho. |
when | Conditional | Đặt quy tắc định dạng có điều kiện để kích hoạt khi dữ liệu đầu vào bắt đầu bằng giá trị đã cho. |
with | Conditional | Đặt quy tắc định dạng có điều kiện theo tiêu chí do các giá trị Boolean xác định, thường 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 một quy tắc định dạng có điều kiện từ các chế độ cài đặt được áp dụng cho trình tạo.
Cầu thủ trả bóng
Conditional
– Biểu thị quy tắc định dạng có điều kiện.
copy()
Trả về một chế độ đặt sẵn của trình tạo quy tắc với các chế độ cài đặt của quy tắc này.
Cầu thủ trả bóng
Conditional
– Trình tạo dựa trên các chế độ cài đặt của quy tắc này.
get Boolean Condition()
Truy xuất thông tin Boolean
của quy tắc nếu quy tắc này sử dụng tiêu chí điều kiện boolean. Nếu không, hàm này sẽ trả về null
.
// Log the boolean criteria type of the first conditional format rules of a // sheet. const rule = SpreadsheetApp.getActiveSheet().getConditionalFormatRules()[0]; const booleanCondition = rule.getBooleanCondition(); if (booleanCondition != null) { Logger.log(booleanCondition.getCriteriaType()); }
Cầu thủ trả bóng
Boolean
– Đố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.
get Gradient Condition()
Truy xuất thông tin Gradient
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àm này sẽ trả về null
.
// Log the gradient minimum color of the first conditional format rule of a // sheet. const rule = SpreadsheetApp.getActiveSheet().getConditionalFormatRules()[0]; const gradientCondition = rule.getGradientCondition(); if (gradientCondition != null) { // Assume the color has ColorType.RGB. Logger.log(gradientCondition.getMinColorObject().asRgbColor().asHexString()); }
Cầu thủ trả bóng
Gradient
– Đố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.
get Ranges()
Truy xuất các dải ô mà quy tắc định dạng có điều kiện này được áp dụng.
// Log each range of the first conditional format rule of a sheet. const rule = SpreadsheetApp.getActiveSheet().getConditionalFormatRules()[0]; const ranges = rule.getRanges(); for (let i = 0; i < ranges.length; i++) { Logger.log(ranges[i].getA1Notation()); }
Cầu thủ trả bóng
Range[]
– Dải ô mà quy tắc định dạng có điều kiện này được áp dụng.
set Background(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 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". const sheet = SpreadsheetApp.getActiveSheet(); const range = sheet.getRange('A1:B3'); const rule = SpreadsheetApp.newConditionalFormatRule() .whenTextEqualTo('hello') .setBackground('#FF0000') .setRanges([range]) .build(); const rules = sheet.getConditionalFormatRules(); rules.push(rule); sheet.setConditionalFormatRules(rules);
Thông số
Tên | Loại | Mô tả |
---|---|---|
color | String | Màu bạn muốn hoặc null để xoá. |
Cầu thủ trả bóng
Conditional
– Trình tạo, để liên kết.
set Background Object(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 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". const sheet = SpreadsheetApp.getActiveSheet(); const range = sheet.getRange('A1:B3'); const color = SpreadsheetApp.newColor() .setThemeColor(SpreadsheetApp.ThemeColorType.BACKGROUND) .build(); const rule = SpreadsheetApp.newConditionalFormatRule() .whenTextEqualTo('hello') .setBackground(color) .setRanges([range]) .build(); const rules = sheet.getConditionalFormatRules(); rules.push(rule); sheet.setConditionalFormatRules(rules);
Thông số
Tên | Loại | Mô tả |
---|---|---|
color | Color | Đối tượng màu hoặc null bạn muốn xoá. |
Cầu thủ trả bóng
Conditional
– Trình tạo, để liên kết.
set Bold(bold)
Đặt chế độ 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 sẽ xoá mọi văn bản in đậm hiện có nếu điều kiện được đáp ứng. 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". const sheet = SpreadsheetApp.getActiveSheet(); const range = sheet.getRange('A1:B3'); const rule = SpreadsheetApp.newConditionalFormatRule() .whenTextEqualTo('hello') .setBold(true) .setRanges([range]) .build(); const rules = sheet.getConditionalFormatRules(); rules.push(rule); sheet.setConditionalFormatRules(rules);
Thông số
Tên | Loại | Mô tả |
---|---|---|
bold | Boolean | Văn bản có được in đậm hay không nếu điều kiện định dạng được đáp ứng; null sẽ xoá chế độ cài đặt này. |
Cầu thủ trả bóng
Conditional
– Trình tạo, để liên kết.
set Font Color(color)
Đặt màu phông chữ cho định dạng của quy tắc định dạng có điều kiện. 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". const sheet = SpreadsheetApp.getActiveSheet(); const range = sheet.getRange('A1:B3'); const rule = SpreadsheetApp.newConditionalFormatRule() .whenTextEqualTo('hello') .setFontColor('#FF0000') .setRanges([range]) .build(); const rules = sheet.getConditionalFormatRules(); rules.push(rule); sheet.setConditionalFormatRules(rules);
Thông số
Tên | Loại | Mô tả |
---|---|---|
color | String | Màu bạn muốn hoặc null để xoá. |
Cầu thủ trả bóng
Conditional
– Trình tạo, để liên kết.
set Font Color Object(color)
Đặt màu phông chữ cho định dạng của quy tắc định dạng có điều kiện. 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". const sheet = SpreadsheetApp.getActiveSheet(); const range = sheet.getRange('A1:B3'); const color = SpreadsheetApp.newColor() .setThemeColor(SpreadsheetApp.ThemeColorType.TEXT) .build(); const rule = SpreadsheetApp.newConditionalFormatRule() .whenTextEqualTo('hello') .setFontColor(color) .setRanges([range]) .build(); const rules = sheet.getConditionalFormatRules(); rules.push(rule); sheet.setConditionalFormatRules(rules);
Thông số
Tên | Loại | Mô tả |
---|---|---|
color | Color | Đối tượng màu hoặc null bạn muốn xoá. |
Cầu thủ trả bóng
Conditional
– Trình tạo, để liên kết.
set Gradient Maxpoint(color)
Xoá giá trị điểm tối đa của dải màu trong quy tắc định dạng có điều kiện và thay vào đó, sử dụng giá trị tối đa trong các dải của quy tắc. Đồng thời đặt màu điểm lớn nhất của độ dốc 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. const sheet = SpreadsheetApp.getActiveSheet(); const range = sheet.getRange('A1:B3'); const rule = SpreadsheetApp.newConditionalFormatRule() .setGradientMaxpoint('#FF0000') .setGradientMinpoint('#FFFFFF') .setRanges([range]) .build(); const rules = sheet.getConditionalFormatRules(); rules.push(rule); sheet.setConditionalFormatRules(rules);
Thông số
Tên | Loại | Mô tả |
---|---|---|
color | String | Màu điểm tối đa cần đặt. |
Cầu thủ trả bóng
Conditional
– Trình tạo, để liên kết.
set Gradient Maxpoint Object(color)
Xoá giá trị điểm tối đa của dải màu trong quy tắc định dạng có điều kiện và thay vào đó, sử dụng giá trị tối đa trong các dải của quy tắc. Đồng thời đặt màu điểm lớn nhất của độ dốc 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. const sheet = SpreadsheetApp.getActiveSheet(); const range = sheet.getRange('A1:B3'); const textColor = SpreadsheetApp.newColor() .setThemeColor(SpreadsheetApp.ThemeColorType.TEXT) .build(); const backgroundColor = SpreadsheetApp.newColor() .setThemeColor(SpreadsheetApp.ThemeColorType.BACKGROUND) .build(); const rule = SpreadsheetApp.newConditionalFormatRule() .setGradientMaxpoint(textColor) .setGradientMinpoint(backgroundColor) .setRanges([range]) .build(); const rules = sheet.getConditionalFormatRules(); rules.push(rule); sheet.setConditionalFormatRules(rules);
Thông số
Tên | Loại | Mô tả |
---|---|---|
color | Color | Đối tượng màu maxpoint cần đặt. |
Cầu thủ trả bóng
Conditional
– Trình tạo, để liên kết.
set Gradient Maxpoint Object With Value(color, type, value)
Đặt các trường điểm tối đa của dải màu trong 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. const sheet = SpreadsheetApp.getActiveSheet(); const range = sheet.getRange('A1:B3'); const color1 = SpreadsheetApp.newColor() .setThemeColor(SpreadsheetApp.ThemeColorType.ACCENT1) .build(); const color2 = SpreadsheetApp.newColor() .setThemeColor(SpreadsheetApp.ThemeColorType.ACCENT2) .build(); const color3 = SpreadsheetApp.newColor() .setThemeColor(SpreadsheetApp.ThemeColorType.ACCENT3) .build(); const rule = SpreadsheetApp.newConditionalFormatRule() .setGradientMaxpointWithValue( color1, SpreadsheetApp.InterpolationType.NUMBER, '100', ) .setGradientMidpointWithValue( color2, SpreadsheetApp.InterpolationType.NUMBER, '50', ) .setGradientMinpointWithValue( color3, SpreadsheetApp.InterpolationType.NUMBER, '0', ) .setRanges([range]) .build(); const rules = sheet.getConditionalFormatRules(); rules.push(rule); sheet.setConditionalFormatRules(rules);
Thông số
Tên | Loại | Mô tả |
---|---|---|
color | Color | Màu điểm tối đa cần đặt. |
type | Interpolation | Loại nội suy maxpoint cần đặt. |
value | String | Giá trị điểm tối đa cần đặt. |
Cầu thủ trả bóng
Conditional
– Trình tạo, để liên kết.
set Gradient Maxpoint With Value(color, type, value)
Đặt các trường điểm tối đa của dải màu trong 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. const sheet = SpreadsheetApp.getActiveSheet(); const range = sheet.getRange('A1:B3'); const rule = SpreadsheetApp.newConditionalFormatRule() .setGradientMaxpointWithValue( '#0000FF', SpreadsheetApp.InterpolationType.NUMBER, '100', ) .setGradientMidpointWithValue( '#00FF00', SpreadsheetApp.InterpolationType.NUMBER, '50', ) .setGradientMinpointWithValue( '#FF0000', SpreadsheetApp.InterpolationType.NUMBER, '0', ) .setRanges([range]) .build(); const rules = sheet.getConditionalFormatRules(); rules.push(rule); sheet.setConditionalFormatRules(rules);
Thông số
Tên | Loại | Mô tả |
---|---|---|
color | String | Màu điểm tối đa cần đặt. |
type | Interpolation | Loại nội suy maxpoint cần đặt. |
value | String | Giá trị điểm tối đa cần đặt. |
Cầu thủ trả bóng
Conditional
– Trình tạo, để liên kết.
set Gradient Midpoint Object With Value(color, type, value)
Đặt các trường trung điểm của dải màu trong 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 được truyền vào 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. const sheet = SpreadsheetApp.getActiveSheet(); const range = sheet.getRange('A1:B3'); const color1 = SpreadsheetApp.newColor() .setThemeColor(SpreadsheetApp.ThemeColorType.ACCENT1) .build(); const color2 = SpreadsheetApp.newColor() .setThemeColor(SpreadsheetApp.ThemeColorType.ACCENT2) .build(); const color3 = SpreadsheetApp.newColor() .setThemeColor(SpreadsheetApp.ThemeColorType.ACCENT3) .build(); const rule = SpreadsheetApp.newConditionalFormatRule() .setGradientMaxpointWithValue( color1, SpreadsheetApp.InterpolationType.NUMBER, '100', ) .setGradientMidpointWithValue( color2, SpreadsheetApp.InterpolationType.NUMBER, '50', ) .setGradientMinpointWithValue( color3, SpreadsheetApp.InterpolationType.NUMBER, '0', ) .setRanges([range]) .build(); const rules = sheet.getConditionalFormatRules(); rules.push(rule); sheet.setConditionalFormatRules(rules);
Thông số
Tên | Loại | Mô tả |
---|---|---|
color | Color | Màu điểm trung bình cần đặt. |
type | Interpolation | Loại nội suy điểm giữa cần đặt hoặc null để xoá. |
value | String | Giá trị trung điểm cần đặt. |
Cầu thủ trả bóng
Conditional
– Trình tạo, để liên kết.
set Gradient Midpoint With Value(color, type, value)
Đặt các trường trung điểm của dải màu trong 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 được truyền vào 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. const sheet = SpreadsheetApp.getActiveSheet(); const range = sheet.getRange('A1:B3'); const rule = SpreadsheetApp.newConditionalFormatRule() .setGradientMaxpointWithValue( '#0000FF', SpreadsheetApp.InterpolationType.NUMBER, '100', ) .setGradientMidpointWithValue( '#00FF00', SpreadsheetApp.InterpolationType.NUMBER, '50', ) .setGradientMinpointWithValue( '#FF0000', SpreadsheetApp.InterpolationType.NUMBER, '0', ) .setRanges([range]) .build(); const rules = sheet.getConditionalFormatRules(); rules.push(rule); sheet.setConditionalFormatRules(rules);
Thông số
Tên | Loại | Mô tả |
---|---|---|
color | String | Màu điểm trung bình cần đặt. |
type | Interpolation | Loại nội suy điểm giữa cần đặt hoặc null để xoá. |
value | String | Giá trị trung điểm cần đặt. |
Cầu thủ trả bóng
Conditional
– Trình tạo, để liên kết.
set Gradient Minpoint(color)
Xoá giá trị điểm tối thiểu của dải màu trong 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 các dải của quy tắc. Đồng thời đặt màu điểm nhỏ nhất của độ dốc 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. const sheet = SpreadsheetApp.getActiveSheet(); const range = sheet.getRange('A1:B3'); const rule = SpreadsheetApp.newConditionalFormatRule() .setGradientMaxpoint('#FF0000') .setGradientMinpoint('#FFFFFF') .setRanges([range]) .build(); const rules = sheet.getConditionalFormatRules(); rules.push(rule); sheet.setConditionalFormatRules(rules);
Thông số
Tên | Loại | Mô tả |
---|---|---|
color | String | Màu điểm nhỏ nhất cần đặt. |
Cầu thủ trả bóng
Conditional
– Trình tạo, để liên kết.
set Gradient Minpoint Object(color)
Xoá giá trị điểm tối thiểu của dải màu trong 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 các dải của quy tắc. Đồng thời đặt màu điểm nhỏ nhất của độ dốc 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. const sheet = SpreadsheetApp.getActiveSheet(); const range = sheet.getRange('A1:B3'); const textColor = SpreadsheetApp.newColor() .setThemeColor(SpreadsheetApp.ThemeColorType.TEXT) .build(); const backgroundColor = SpreadsheetApp.newColor() .setThemeColor(SpreadsheetApp.ThemeColorType.BACKGROUND) .build(); const rule = SpreadsheetApp.newConditionalFormatRule() .setGradientMaxpoint(textColor) .setGradientMinpoint(backgroundColor) .setRanges([range]) .build(); const rules = sheet.getConditionalFormatRules(); rules.push(rule); sheet.setConditionalFormatRules(rules);
Thông số
Tên | Loại | Mô tả |
---|---|---|
color | Color | Đối tượng màu minpoint cần đặt. |
Cầu thủ trả bóng
Conditional
– Trình tạo, để liên kết.
set Gradient Minpoint Object With Value(color, type, value)
Đặt các trường minpoint của dải màu trong 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. const sheet = SpreadsheetApp.getActiveSheet(); const range = sheet.getRange('A1:B3'); const color1 = SpreadsheetApp.newColor() .setThemeColor(SpreadsheetApp.ThemeColorType.ACCENT1) .build(); const color2 = SpreadsheetApp.newColor() .setThemeColor(SpreadsheetApp.ThemeColorType.ACCENT2) .build(); const color3 = SpreadsheetApp.newColor() .setThemeColor(SpreadsheetApp.ThemeColorType.ACCENT3) .build(); const rule = SpreadsheetApp.newConditionalFormatRule() .setGradientMaxpointWithValue( color1, SpreadsheetApp.InterpolationType.NUMBER, '100', ) .setGradientMidpointWithValue( color2, SpreadsheetApp.InterpolationType.NUMBER, '50', ) .setGradientMinpointWithValue( color3, SpreadsheetApp.InterpolationType.NUMBER, '0', ) .setRanges([range]) .build(); const rules = sheet.getConditionalFormatRules(); rules.push(rule); sheet.setConditionalFormatRules(rules);
Thông số
Tên | Loại | Mô tả |
---|---|---|
color | Color | Màu điểm nhỏ nhất cần đặt. |
type | Interpolation | Loại nội suy minpoint cần đặt. |
value | String | Giá trị điểm nhỏ nhất cần đặt. |
Cầu thủ trả bóng
Conditional
– Trình tạo, để liên kết.
set Gradient Minpoint With Value(color, type, value)
Đặt các trường minpoint của dải màu trong 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. const sheet = SpreadsheetApp.getActiveSheet(); const range = sheet.getRange('A1:B3'); const rule = SpreadsheetApp.newConditionalFormatRule() .setGradientMaxpointWithValue( '#0000FF', SpreadsheetApp.InterpolationType.NUMBER, '100', ) .setGradientMidpointWithValue( '#00FF00', SpreadsheetApp.InterpolationType.NUMBER, '50', ) .setGradientMinpointWithValue( '#FF0000', SpreadsheetApp.InterpolationType.NUMBER, '0', ) .setRanges([range]) .build(); const rules = sheet.getConditionalFormatRules(); rules.push(rule); sheet.setConditionalFormatRules(rules);
Thông số
Tên | Loại | Mô tả |
---|---|---|
color | String | Màu điểm nhỏ nhất cần đặt. |
type | Interpolation | Loại nội suy minpoint cần đặt. |
value | String | Giá trị điểm nhỏ nhất cần đặt. |
Cầu thủ trả bóng
Conditional
– Trình tạo, để liên kết.
set Italic(italic)
Đặt văn bản 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 sẽ in nghiêng văn bản nếu điều kiện được đáp ứng; nếu false
, quy tắc sẽ xoá mọi kiểu in nghiêng hiện có nếu điều kiện được đáp ứng. Truyền vào null
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". const sheet = SpreadsheetApp.getActiveSheet(); const range = sheet.getRange('A1:B3'); const rule = SpreadsheetApp.newConditionalFormatRule() .whenTextEqualTo('hello') .setItalic(true) .setRanges([range]) .build(); const rules = sheet.getConditionalFormatRules(); rules.push(rule); sheet.setConditionalFormatRules(rules);
Thông số
Tên | Loại | Mô tả |
---|---|---|
italic | Boolean | Văn bản có nên được in nghiêng hay không nếu điều kiện định dạng được đáp ứng; null sẽ xoá chế độ cài đặt này. |
Cầu thủ trả bóng
Conditional
– Trình tạo, để liên kết.
set Ranges(ranges)
Đặt một hoặc nhiều dải ô mà quy tắc định dạng có điều kiện này được áp dụng. Thao tác này sẽ thay thế mọi dải ô hiện có. Việc đặt một mảng trống sẽ xoá mọi dải ô hiện có. Một quy tắc phải có ít nhất một dải ô.
// Adds a conditional format rule to a sheet that causes cells in range A1:B3 // and range D4:F6 to turn red if they contain a number between 1 and 10. const sheet = SpreadsheetApp.getActiveSheet(); const rangeOne = sheet.getRange('A1:B3'); const rangeTwo = sheet.getRange('D4:F6'); const rule = SpreadsheetApp.newConditionalFormatRule() .whenNumberBetween(1, 10) .setBackground('#FF0000') .setRanges([rangeOne, rangeTwo]) .build(); const rules = sheet.getConditionalFormatRules(); rules.push(rule); sheet.setConditionalFormatRules(rules);
Thông số
Tên | Loại | Mô tả |
---|---|---|
ranges | Range[] | Các dải ô mà quy tắc định dạng có điều kiện này được áp dụng. |
Cầu thủ trả bóng
Conditional
– Trình tạo, để liên kết.
set Strikethrough(strikethrough)
Đặt hiệu ứng gạch ngang cho văn bản trong định dạng của quy tắc định dạng có điều kiện. Nếu strikethrough
là true
, quy tắc sẽ gạch ngang văn bản nếu điều kiện được đáp ứng; nếu là false
, quy tắc sẽ xoá mọi định dạng gạch ngang hiện có nếu điều kiện được đáp ứng. 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". const sheet = SpreadsheetApp.getActiveSheet(); const range = sheet.getRange('A1:B3'); const rule = SpreadsheetApp.newConditionalFormatRule() .whenTextEqualTo('hello') .setStrikethrough(true) .setRanges([range]) .build(); const rules = sheet.getConditionalFormatRules(); rules.push(rule); sheet.setConditionalFormatRules(rules);
Thông số
Tên | Loại | Mô tả |
---|---|---|
strikethrough | Boolean | Có nên gạch ngang văn bản hay không nếu điều kiện định dạng được đáp ứng; null sẽ xoá chế độ cài đặt này. |
Cầu thủ trả bóng
Conditional
– Trình tạo, để liên kết.
set Underline(underline)
Đặt chế độ gạch chân văn bản 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 điều kiện được đáp ứng; nếu false
, quy tắc sẽ xoá mọi dấu gạch chân hiện có nếu điều kiện được đáp ứng. Truyền vào null
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". const sheet = SpreadsheetApp.getActiveSheet(); const range = sheet.getRange('A1:B3'); const rule = SpreadsheetApp.newConditionalFormatRule() .whenTextEqualTo('hello') .setUnderline(true) .setRanges([range]) .build(); const rules = sheet.getConditionalFormatRules(); rules.push(rule); sheet.setConditionalFormatRules(rules);
Thông số
Tên | Loại | Mô tả |
---|---|---|
underline | Boolean | Văn bản có được gạch chân hay không nếu điều kiện định dạng được đáp ứng; null sẽ xoá chế độ cài đặt này. |
Cầu thủ trả bóng
Conditional
– Trình tạo, để liên kết.
when Cell Empty()
Đặ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. const sheet = SpreadsheetApp.getActiveSheet(); const range = sheet.getRange('A1:B3'); const rule = SpreadsheetApp.newConditionalFormatRule() .whenCellEmpty() .setBackground('#FF0000') .setRanges([range]) .build(); const rules = sheet.getConditionalFormatRules(); rules.push(rule); sheet.setConditionalFormatRules(rules);
Cầu thủ trả bóng
Conditional
– Trình tạo, để liên kết.
when Cell Not Empty()
Đặ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. const sheet = SpreadsheetApp.getActiveSheet(); const range = sheet.getRange('A1:B3'); const rule = SpreadsheetApp.newConditionalFormatRule() .whenCellNotEmpty() .setBackground('#FF0000') .setRanges([range]) .build(); const rules = sheet.getConditionalFormatRules(); rules.push(rule); sheet.setConditionalFormatRules(rules);
Cầu thủ trả bóng
Conditional
– Trình tạo, để liên kết.
when Date After(date)
Đặt quy tắc định dạng có điều kiện để kích hoạt khi 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. const sheet = SpreadsheetApp.getActiveSheet(); const range = sheet.getRange('A1:B3'); const rule = SpreadsheetApp.newConditionalFormatRule() .whenDateAfter(new Date('11/4/1993')) .setBackground('#FF0000') .setRanges([range]) .build(); const rules = sheet.getConditionalFormatRules(); rules.push(rule); sheet.setConditionalFormatRules(rules);
Thông số
Tên | Loại | Mô tả |
---|---|---|
date | Date | Ngày mới nhất. |
Cầu thủ trả bóng
Conditional
– Trình tạo, để liên kết.
when Date After(date)
Đặt quy tắc định dạng có điều kiện để kích hoạt khi 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. const sheet = SpreadsheetApp.getActiveSheet(); const range = sheet.getRange('A1:B3'); const rule = SpreadsheetApp.newConditionalFormatRule() .whenDateAfter(SpreadsheetApp.RelativeDate.TODAY) .setBackground('#FF0000') .setRanges([range]) .build(); const rules = sheet.getConditionalFormatRules(); rules.push(rule); sheet.setConditionalFormatRules(rules);
Thông số
Tên | Loại | Mô tả |
---|---|---|
date | Relative | Ngày mới nhất so với loại ngày đã chọn. |
Cầu thủ trả bóng
Conditional
– Trình tạo, để liên kết.
when Date Before(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 đã cho.
// Adds a conditional format rule to a sheet that causes cells in range A1:B3 to // turn red if they contain a date before 11/4/1993. const sheet = SpreadsheetApp.getActiveSheet(); const range = sheet.getRange('A1:B3'); const rule = SpreadsheetApp.newConditionalFormatRule() .whenDateBefore(new Date('11/4/1993')) .setBackground('#FF0000') .setRanges([range]) .build(); const rules = sheet.getConditionalFormatRules(); rules.push(rule); sheet.setConditionalFormatRules(rules);
Thông số
Tên | Loại | Mô tả |
---|---|---|
date | Date | Ngày sớm nhất không được chấp nhận. |
Cầu thủ trả bóng
Conditional
– Trình tạo, để liên kết.
when Date Before(date)
Đặt quy tắc định dạng có điều kiện để kích hoạt khi ngày trước 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 before today. const sheet = SpreadsheetApp.getActiveSheet(); const range = sheet.getRange('A1:B3'); const rule = SpreadsheetApp.newConditionalFormatRule() .whenDateBefore(SpreadsheetApp.RelativeDate.TODAY) .setBackground('#FF0000') .setRanges([range]) .build(); const rules = sheet.getConditionalFormatRules(); rules.push(rule); sheet.setConditionalFormatRules(rules);
Thông số
Tên | Loại | Mô tả |
---|---|---|
date | Relative | Ngày mới nhất so với loại ngày đã chọn. |
Cầu thủ trả bóng
Conditional
– Trình tạo, để liên kết.
when Date Equal To(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 đã cho.
// Adds a conditional format rule to a sheet that causes cells in range A1:B3 to // turn red if they contain the date 11/4/1993. const sheet = SpreadsheetApp.getActiveSheet(); const range = sheet.getRange('A1:B3'); const rule = SpreadsheetApp.newConditionalFormatRule() .whenDateEqualTo(new Date('11/4/1993')) .setBackground('#FF0000') .setRanges([range]) .build(); const rules = sheet.getConditionalFormatRules(); rules.push(rule); sheet.setConditionalFormatRules(rules);
Thông số
Tên | Loại | Mô tả |
---|---|---|
date | Date | Ngày duy nhất được chấp nhận. |
Cầu thủ trả bóng
Conditional
– Trình tạo, để liên kết.
when Date Equal To(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. const sheet = SpreadsheetApp.getActiveSheet(); const range = sheet.getRange('A1:B3'); const rule = SpreadsheetApp.newConditionalFormatRule() .whenDateEqualTo(SpreadsheetApp.RelativeDate.TODAY) .setBackground('#FF0000') .setRanges([range]) .build(); const rules = sheet.getConditionalFormatRules(); rules.push(rule); sheet.setConditionalFormatRules(rules);
Thông số
Tên | Loại | Mô tả |
---|---|---|
date | Relative | Ngày mới nhất so với loại ngày đã chọn. |
Cầu thủ trả bóng
Conditional
– Trình tạo, để liên kết.
when Formula Satisfied(formula)
Đặt quy tắc định dạng có điều kiện để kích hoạt khi công thức đã cho đánh giá thành true
.
// Adds a conditional format rule to a sheet that causes cells in range A1:B3 to // turn red if they satisfy the condition "=EQ(B4, C3)". const sheet = SpreadsheetApp.getActiveSheet(); const range = sheet.getRange('A1:B3'); const rule = SpreadsheetApp.newConditionalFormatRule() .whenFormulaSatisfied('=EQ(B4, C3)') .setBackground('#FF0000') .setRanges([range]) .build(); const rules = sheet.getConditionalFormatRules(); rules.push(rule); sheet.setConditionalFormatRules(rules);
Thông số
Tên | Loại | Mô tả |
---|---|---|
formula | String | Một công thức tuỳ chỉnh đánh giá là true nếu dữ liệu đầu vào hợp lệ. |
Cầu thủ trả bóng
Conditional
– Trình tạo, để liên kết.
when Number Between(start, end)
Đặt quy tắc định dạng có điều kiện để kích hoạt khi một số nằm trong khoảng 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. const sheet = SpreadsheetApp.getActiveSheet(); const range = sheet.getRange('A1:B3'); const rule = SpreadsheetApp.newConditionalFormatRule() .whenNumberBetween(1, 10) .setBackground('#FF0000') .setRanges([range]) .build(); const rules = sheet.getConditionalFormatRules(); rules.push(rule); sheet.setConditionalFormatRules(rules);
Thông số
Tên | Loại | Mô tả |
---|---|---|
start | Number | Giá trị thấp nhất có thể chấp nhận. |
end | Number | Giá trị cao nhất có thể chấp nhận. |
Cầu thủ trả bóng
Conditional
– Trình tạo, để liên kết.
when Number Equal To(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. const sheet = SpreadsheetApp.getActiveSheet(); const range = sheet.getRange('A1:B3'); const rule = SpreadsheetApp.newConditionalFormatRule() .whenNumberEqualTo(10) .setBackground('#FF0000') .setRanges([range]) .build(); const rules = sheet.getConditionalFormatRules(); rules.push(rule); sheet.setConditionalFormatRules(rules);
Thông số
Tên | Loại | Mô tả |
---|---|---|
number | Number | Giá trị duy nhất được chấp nhận. |
Cầu thủ trả bóng
Conditional
– Trình tạo, để liên kết.
when Number Greater Than(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. const sheet = SpreadsheetApp.getActiveSheet(); const range = sheet.getRange('A1:B3'); const rule = SpreadsheetApp.newConditionalFormatRule() .whenNumberGreaterThan(10) .setBackground('#FF0000') .setRanges([range]) .build(); const rules = sheet.getConditionalFormatRules(); rules.push(rule); sheet.setConditionalFormatRules(rules);
Thông số
Tên | Loại | Mô tả |
---|---|---|
number | Number | Giá trị cao nhất không được chấp nhận. |
Cầu thủ trả bóng
Conditional
– Trình tạo, để liên kết.
when Number Greater Than Or Equal To(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. const sheet = SpreadsheetApp.getActiveSheet(); const range = sheet.getRange('A1:B3'); const rule = SpreadsheetApp.newConditionalFormatRule() .whenNumberGreaterThanOrEqualTo(10) .setBackground('#FF0000') .setRanges([range]) .build(); const rules = sheet.getConditionalFormatRules(); rules.push(rule); sheet.setConditionalFormatRules(rules);
Thông số
Tên | Loại | Mô tả |
---|---|---|
number | Number | Giá trị thấp nhất có thể chấp nhận. |
Cầu thủ trả bóng
Conditional
– Trình tạo, để liên kết.
when Number Less Than(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. const sheet = SpreadsheetApp.getActiveSheet(); const range = sheet.getRange('A1:B3'); const rule = SpreadsheetApp.newConditionalFormatRule() .whenNumberLessThan(10) .setBackground('#FF0000') .setRanges([range]) .build(); const rules = sheet.getConditionalFormatRules(); rules.push(rule); sheet.setConditionalFormatRules(rules);
Thông số
Tên | Loại | Mô tả |
---|---|---|
number | Number | Giá trị thấp nhất không được chấp nhận. |
Cầu thủ trả bóng
Conditional
– Trình tạo, để liên kết.
when Number Less Than Or Equal To(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. const sheet = SpreadsheetApp.getActiveSheet(); const range = sheet.getRange('A1:B3'); const rule = SpreadsheetApp.newConditionalFormatRule() .whenNumberLessThanOrEqualTo(10) .setBackground('#FF0000') .setRanges([range]) .build(); const rules = sheet.getConditionalFormatRules(); rules.push(rule); sheet.setConditionalFormatRules(rules);
Thông số
Tên | Loại | Mô tả |
---|---|---|
number | Number | Giá trị cao nhất có thể chấp nhận. |
Cầu thủ trả bóng
Conditional
– Trình tạo, để liên kết.
when Number Not Between(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 phải 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 not between 1 and 10. const sheet = SpreadsheetApp.getActiveSheet(); const range = sheet.getRange('A1:B3'); const rule = SpreadsheetApp.newConditionalFormatRule() .whenNumberNotBetween(1, 10) .setBackground('#FF0000') .setRanges([range]) .build(); const rules = sheet.getConditionalFormatRules(); rules.push(rule); sheet.setConditionalFormatRules(rules);
Thông số
Tên | Loại | 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
Conditional
– Trình tạo, để liên kết.
when Number Not Equal To(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 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 don't contain the number 10. const sheet = SpreadsheetApp.getActiveSheet(); const range = sheet.getRange('A1:B3'); const rule = SpreadsheetApp.newConditionalFormatRule() .whenNumberNotEqualTo(10) .setBackground('#FF0000') .setRanges([range]) .build(); const rules = sheet.getConditionalFormatRules(); rules.push(rule); sheet.setConditionalFormatRules(rules);
Thông số
Tên | Loại | Mô tả |
---|---|---|
number | Number | Giá trị duy nhất không được chấp nhận. |
Cầu thủ trả bóng
Conditional
– Trình tạo, để liên kết.
when Text Contains(text)
Đặt quy tắc định dạng có điều kiện để kích hoạt khi dữ liệu đầu vào 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". const sheet = SpreadsheetApp.getActiveSheet(); const range = sheet.getRange('A1:B3'); const rule = SpreadsheetApp.newConditionalFormatRule() .whenTextContains('hello') .setBackground('#FF0000') .setRanges([range]) .build(); const rules = sheet.getConditionalFormatRules(); rules.push(rule); sheet.setConditionalFormatRules(rules);
Thông số
Tên | Loại | Mô tả |
---|---|---|
text | String | Giá trị mà dữ liệu đầu vào phải chứa. |
Cầu thủ trả bóng
Conditional
– Trình tạo, để liên kết.
when Text Does Not Contain(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". const sheet = SpreadsheetApp.getActiveSheet(); const range = sheet.getRange('A1:B3'); const rule = SpreadsheetApp.newConditionalFormatRule() .whenTextDoesNotContain('hello') .setBackground('#FF0000') .setRanges([range]) .build(); const rules = sheet.getConditionalFormatRules(); rules.push(rule); sheet.setConditionalFormatRules(rules);
Thông số
Tên | Loại | Mô tả |
---|---|---|
text | String | Giá trị mà dữ liệu đầu vào không được chứa. |
Cầu thủ trả bóng
Conditional
– Trình tạo, để liên kết.
when Text Ends With(text)
Đặt quy tắc định dạng có điều kiện để kích hoạt khi dữ liệu đầu vào 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". const sheet = SpreadsheetApp.getActiveSheet(); const range = sheet.getRange('A1:B3'); const rule = SpreadsheetApp.newConditionalFormatRule() .whenTextEndsWith('hello') .setBackground('#FF0000') .setRanges([range]) .build(); const rules = sheet.getConditionalFormatRules(); rules.push(rule); sheet.setConditionalFormatRules(rules);
Thông số
Tên | Loại | Mô tả |
---|---|---|
text | String | Văn bản cần so sánh với phần cuối của chuỗi. |
Cầu thủ trả bóng
Conditional
– Trình tạo, để liên kết.
when Text Equal To(text)
Đặt quy tắc định dạng có điều kiện để kích hoạt khi dữ liệu đầu vào 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 have text equal to "hello". const sheet = SpreadsheetApp.getActiveSheet(); const range = sheet.getRange('A1:B3'); const rule = SpreadsheetApp.newConditionalFormatRule() .whenTextEqualTo('hello') .setBackground('#FF0000') .setRanges([range]) .build(); const rules = sheet.getConditionalFormatRules(); rules.push(rule); sheet.setConditionalFormatRules(rules);
Thông số
Tên | Loại | Mô tả |
---|---|---|
text | String | Giá trị duy nhất được chấp nhận. |
Cầu thủ trả bóng
Conditional
– Trình tạo, để liên kết.
when Text Starts With(text)
Đặt quy tắc định dạng có điều kiện để kích hoạt khi dữ liệu đầu vào 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". const sheet = SpreadsheetApp.getActiveSheet(); const range = sheet.getRange('A1:B3'); const rule = SpreadsheetApp.newConditionalFormatRule() .whenTextStartsWith('hello') .setBackground('#FF0000') .setRanges([range]) .build(); const rules = sheet.getConditionalFormatRules(); rules.push(rule); sheet.setConditionalFormatRules(rules);
Thông số
Tên | Loại | Mô tả |
---|---|---|
text | String | Văn bản cần so sánh với phần đầu của chuỗi. |
Cầu thủ trả bóng
Conditional
– Trình tạo, để liên kết.
with Criteria(criteria, args)
Đặt quy tắc định dạng có điều kiện theo tiêu chí do các giá trị Boolean
xác định, thường 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. const sheet = SpreadsheetApp.getActiveSheet(); const rules = sheet.getConditionalFormatRules(); const booleanCondition = rules[0].getBooleanCondition(); if (booleanCondition != null) { const rule = SpreadsheetApp.newConditionalFormatRule() .withCriteria( booleanCondition.getCriteriaType(), booleanCondition.getCriteriaValues(), ) .setBackground('#000000') .setRanges(rules[0].getRanges()) .build(); rules.push(rule); } sheet.setConditionalFormatRules(rules);
Thông số
Tên | Loại | Mô tả |
---|---|---|
criteria | Boolean | 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 đối số tương ứng với phương thức when...() tương ứng ở trên. |
Cầu thủ trả bóng
Conditional
– Trình tạo, để liên kết.