我正在尝试使用 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();
答案 0 :(得分:2)
此示例创建一个条件格式规则,该规则为范围内的值设置从绿色到红色的颜色渐变。最低值为绿色,最高值为红色。
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]);
};