google-apps-script - 谷歌脚本: How to implement conditional formatting into spreadsheet

标签 google-apps-script google-sheets google-sheets-api gs-conditional-formatting

数据:

  • B1: =GoogleClock//此函数实时显示小时。 2013年11月28日15:45:00
  • C3: 0:15:00//时间(以小时为单位)
  • E3:2013年11月28日15:45:00
  • F3: =SUM(E3+C3)//结果为 28/11/2013 16:00:00
  • G3: =IF(C3>0;IF($B$1>=$F3;"调用";"及时");"")

公式将检查 B1 >= F3 是否,如果未及时,结果将调用。

正如您在此示例中看到的,现在是 15:45,G3 将显示“In Time”,但当 =googleclock 函数标记 28/11/2013 16:00:00 时,G3 会将值更改为 Call。在那一刻背景应该从绿色变为红色-

情况:

I have a formula in the Column G, the result of that formula "Call" or "In Time".

I set a conditional formatting using Menu > Format > Conditional Formatting to Column G. but the conditional only work for the existing rows.

问题:

If I add new rows the Conditional Formatting is not set to that news rows.

解决方案是创建一个脚本来检测单元格中的值,如果“值”是“调用”,则将背景颜色设置为红色,如果“及时”,则将背景颜色设置为绿色。

如果我将此脚本设置为在 OnEdit 中运行或每 5 分钟或每分钟运行一次,系统会变慢,因为此脚本每次都会检查该值。

是否有任何方法可以像我从菜单中设置的那样设置条件格式?

最佳答案

Range.copyTo()可以复制条件格式。

例如,此代码段会将条件格式从单元格 A1 复制到该列的其余部分:

function copyFormat() {
  var source = ss.getRange('A1');
  var destination = ss.getRange('A2:A');
  source.copyTo(destination, {formatOnly:true});
}

关于google-apps-script - 谷歌脚本: How to implement conditional formatting into spreadsheet,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20273493/

相关文章:

javascript - 未捕获的 TypeError : google. script.run。不是函数

google-sheets - 如果当前单元格存在于某个范围内,则在 Google Docs 中应用条件格式

javascript - 为什么 Google 电子表格中的这些单元格比较相等?

excel - Google 表格是否具有与 Excel 中的 WEBSERVICE 和 FILTERXML 等效的功能?

ios - 添加、更新有效,但如何使用 iOS Google Sheets API v4 进行追加?

java - 使用 Sheets API v4 Java 阅读整个 Google 电子表格

google-sheets - Google 电子表格时间驱动事件不会触发

google-apps-script - 我是否正确使用了 Google Apps 脚本锁定服务?

javascript - 为什么我的 Scriptlet 无法正常工作 html Apps 脚本

javascript - 脚本已完成但返回值不是受支持的返回类型