0

我一直在尝试在我的电子表格上实现一个条件,基本上是一个带有三个条件单元格的检查表,其中包含“是”或“否”。我想要实现的(使用onEdit)是一个所有三个单元格都包含“是”,输入下一列,最后输入“是”的日期。我已经设法创建了其他运行良好的脚本,但是这个让我很难过。

谢谢

4

1 回答 1

1

由于可以单独编辑单元格,因此您的 onEdit 将始终需要检查所有条件单元格的值,并且仅在全部为“是”时才写入时间戳。

function onEdit(event) {
  var conditionalCells = [ "B1", "B2", "B3" ];  // Array of monitored conditionals
  var inList = false;                           // assume edit was outside of the conditionals
  var allYes = true;                            // and that all values are "Yes".
  var sheet = event.source;  // Sheet that was edited
  var cell = event.range.getA1Notation();  // get range description
  // Loop through all conditionals checking their contents.
  // Verify that the edit that triggered onEdit() was in one
  // of our conditional cells, setting inList true if it was.
  for (var i = 0; i < conditionalCells.length && allYes; i++) {
    if (cell == conditionalCells[i]) inList = true;
    allYes = (sheet.getRange(conditionalCells[i]).getValue() == "Yes");
  };
  // If this was our final Yes, record the date.
  // By validating inList, we ensure we record only the first time
  // all conditionals are "Yes".
  if (inList && allYes) sheet.getRange("C1").setValue(new Date());
}
于 2013-04-18T17:04:37.357 回答