google-apps-script - 使用 onSelectionChange 时我做错了什么

标签 google-apps-script google-sheets triggers

我找到了这个触发器 onSelectionChange(e)在developers.google.com 上,如果选择了单个空单元格,则应将背景设置为红色。我只是复制和粘贴没有得到那个结果。我认为我没有遗漏任何帮助,我们将不胜感激。

/**
 * The event handler triggered when the selection changes in the spreadsheet.
 * @param {Event} e The onSelectionChange event.
 */
function onSelectionChange(e) {
  // Set background to red if a single empty cell is selected.
  var range = e.range;
  if(range.getNumRows() === 1 
      && range.getNumColumns() === 1 
      && range.getCell(1, 1).getValue() === "") {
    range.setBackground("red");
  }
}

最佳答案

更新:

似乎它已完全向所有用户推出。您应该能够在不修改代码的情况下使其工作。 e ,事件对象类似于onEdit事件对象。
onSelectionChange是最近推出的功能。考虑等待几天将该功能推广到您的特定项目和电子表格。

关于google-apps-script - 使用 onSelectionChange 时我做错了什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61408971/

相关文章:

google-apps-script - Google Apps Script : In spreadsheet, 如何选择包含日期格式值的单元格并将其更改为该日期加 7 天(1 周)

javascript - HTML 文件中包含的脚本无法在 Google Apps 脚本 HTMLService 中运行

更新触发器上的 Mysql 更新

email - 在 Google Apps 脚本中命名电子邮件附件

google-sheets - 从一个单元格中抓取文本以在另一个单元格的句子中使用 - Google Sheets

google-apps-script - 如何更新现有行(而不是创建一个新的更新行)

if-statement - 将一系列单元格与单个单元格进行比较,然后递增一个值

WPF 子控件的鼠标悬停触发效果

MySQL 触发器需要调整

javascript - 尝试将 Stripe API key 添加到 Google Apps 脚本中的 UrlFetchApp 时收到 401 'truncated server' 错误