【发布时间】:2019-09-13 17:23:06
【问题描述】:
我正在构建一个电子表格,以根据每个类别的预算值跟踪每个月的费用。如果值小于或等于预算金额,我想突出显示一个绿色的单元格,如果它大于预算金额,我想突出显示红色。
如果我传入金额的数值,我可以让它工作,但是预算偶尔会每月变化,所以我希望能够启动一个新月份的电子表格并让它有条件地格式化基于单元格颜色参考预算单元格。我可以在 excel VBA 中执行此操作,但无法将引用传递给 whenNumberLessThan 函数。
//This errors out on trying to concatenate the row onto what is in the D column
var ruleRed = SpreadsheetApp.newConditionalFormatRuleBuilder()
.whenNumberLessThan("=D".concat(row))
.setBackground("#FF0000")
.setRanges([month.getRange("C".concat(row))])
.build();
//This works with 1200 or any other numeric value
var ruleRed = SpreadsheetApp.newConditionalFormatRuleBuilder()
.whenNumberLessThan(1200)
.setBackground("#FF0000")
.setRanges([month.getRange("C".concat(row))])
.build();
【问题讨论】:
-
whenNumberLessThan方法只接受数值。有一种解决方法,但它要求您使用 Advanced Sheet 服务。见Google Sheets script conditional formatting for whenNumberLessThanOrEqualTo(string)
标签: google-apps-script conditional-formatting