Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-apps-script/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/google-sheets/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google apps script 条件格式取决于相邻单元格中的值_Google Apps Script_Google Sheets_Gs Conditional Formatting - Fatal编程技术网

Google apps script 条件格式取决于相邻单元格中的值

Google apps script 条件格式取决于相邻单元格中的值,google-apps-script,google-sheets,gs-conditional-formatting,Google Apps Script,Google Sheets,Gs Conditional Formatting,我在谷歌电子表格中设置了一个时间记录表。现在,我试图根据电子表格中其他单元格的值实现单元格的条件格式: 如果单元格G2的值大于06:30:00(hh:mm:ss) 来自单元格D2的值小于00:30:00(hh:mm:ss)或单元格D2为空 然后将单元格D2的背景色设置为黄色 如果单元格G2的值大于08:45:00(hh:mm:ss) 来自单元格D2的值小于00:45:00(hh:mm:ss)或单元格D2为空 然后将单元格D2的背景色设置为黄色 如果不满足条件,背景色应重置为无 我知道用公式是不可

我在谷歌电子表格中设置了一个时间记录表。现在,我试图根据电子表格中其他单元格的值实现单元格的条件格式:

如果单元格G2的值大于06:30:00(hh:mm:ss) 来自单元格D2的值小于00:30:00(hh:mm:ss)或单元格D2为空 然后将单元格D2的背景色设置为黄色

如果单元格G2的值大于08:45:00(hh:mm:ss) 来自单元格D2的值小于00:45:00(hh:mm:ss)或单元格D2为空 然后将单元格D2的背景色设置为黄色

如果不满足条件,背景色应重置为无

我知道用公式是不可能的。在谷歌应用程序脚本中有这样做的方法吗?我不是脚本编写者,但知道如何插入片段,如果有人愿意向我解释的话,我可能能够阅读和理解


在搜索类似用例(我找到的唯一谷歌应用程序脚本参考)时,对其功能进行了一般性讨论。

这应该可以通过为以下函数创建onEdit触发器来实现:

function myOnEdit(e) {
  var nextColumnCell = e.range.offset(0, 1);
  if (e.range.getValue() == 'foo') {
    nextColumnCell.setFontWeight('bold');
  } else {
    nextColumnCell.setFontWeight('normal');
  }
}

可以找到更多关于触发器的信息。

不知何故,我也无法在谷歌电子表格中找到直接比较时间的方法。。 但是我可以将
时间
转换为
数字
格式。通过这样做,您将能够比较实体

number
格式中的1等于
time
格式中的00:00,因为1代表12:00am

number
格式中的0.5等于
time
格式中的12:00,因为0.5代表12:00pm

number
格式中的0.25等于
time
格式中的6:00,因为0.5代表上午6:00

它并没有回答主要问题,但我希望它能有所帮助。

现在有了一个公式就可以了

选择ColumnD并从中清除任何现有的CF规则。格式,条件格式…,如果<代码>自定义公式为和

=and(row()<>1,or(and(G1>6.5/24,D1<0.5/24),and(G1>8.75/24,D1<0.75/24)))

=和(行()1,或(和(G1>6.5/24,D18.75/24,D18.75/24,据我所知,这在Google Fusion表格中是不可能的。你不能格式化单元格。你可能想用Google电子表格来完成这项工作。好的,谢谢。我把所有的东西都换成了Google电子表格。我该怎么做呢?Eric:非常感谢你的贡献。我完成后会检查并让你知道。Charles:感谢您编辑链接并添加谷歌应用程序脚本标签。