【问题标题】:newConditionalFormatRule based on value and other cellnewConditionalFormatRule 基于值和其他单元格
【发布时间】:2021-02-08 14:10:48
【问题描述】:
我正在尝试使用 app-script newConditionalFormatRule 根据其他单元格设置单元格的颜色。
假设我有这个:
A1 = 40
B1 = 90
然后我希望 A1 获得绿色,因为它低于 B1。
我想让 B1 变红,因为它比 A1 高。
有没有办法让我在规则集中创建这种行为?
喜欢:
var rule3 = SpreadsheetApp.newConditionalFormatRule()
.//check other cell if greater thing.
.setBackground("#EEED09")
.setRanges([range])
.build();
【问题讨论】:
标签:
google-sheets
google-sheets-api
spreadsheet
【解决方案1】:
本示例创建了一个条件格式规则,该规则为范围内的值设置从绿色到红色的渐变颜色。最低值为绿色,最高值为红色。
function CFtest2() {
var theSheet = SpreadsheetApp.getActive();
var area = theSheet.getRange('A1:B1');
var newRule = SpreadsheetApp.newConditionalFormatRule();
newRule
.setRanges([area])
.setGradientMinpoint('#00FF00')
.setGradientMidpointWithValue('#FFFFFF', SpreadsheetApp.InterpolationType.PERCENTILE, '50')
.setGradientMaxpoint('#FF0000')
.build();
theSheet.getActiveSheet().setConditionalFormatRules([newRule]);
};