使用 onSelectionChange 时我做错了什么

2023-11-25

我发现了这个触发器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是最近推出的功能。考虑等待几天,以便将该功能推广到您的特定项目和电子表格。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

使用 onSelectionChange 时我做错了什么 的相关文章

随机推荐