如何在onChange函数中识别更改的单元格 [英] How to identify changed cell in onChange function

查看:49
本文介绍了如何在onChange函数中识别更改的单元格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试检测两个单元的背景颜色变化.不久前,我创建了以下Google表格功能,并将其添加为可安装的触发器.从电子表格更改时开始,因为在编辑时未检测到单元格颜色更改.我以为它可以用,但是我现在才检查一下,它没有检测到哪个单元格的背景色被更改了,有什么主意吗?

I am trying to detect background color change of two cells. A while back I created the following Google Sheet function and added it as an installable trigger From spreadsheet On change since cell color changes are not detected by on Edit. I thought it worked but I just checked it now, and it is not detecting which cell's background color was changed, Any ideas?

function onChangeInstallable(e) {

  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var activeSheet = ss.getActiveSheet();
  var activeSheetName = activeSheet.getSheetName();

  if (activeSheetName == "Settings") {

    if(e.changeType == "OTHER"){

      // makes it this far ok but following line returns
      // #REF! instead of A1 notation of changed cell.

      var editedRange = SpreadsheetApp.getActiveRange().getA1Notation();

      if (editedRange == 'B43' || editedRange == 'B44'){

        setBackgroundColors();

      }
    }
  }
}

还尝试了以下操作,但它返回单元格引用超出范围"错误.

Also tried the following, but it returns a "Cell reference out of range" error.

var editedRange = activeSheet.getActiveCell().getA1Notation();

推荐答案

编辑:看起来这种情况仍然没有解决,请在

edit: looks like this case is still broken, star issue 3269 to vote for a fix

尝试 var editedRange = activeSheet.getActiveRange().getA1Notation();

活动电子表格也已经与 e 对象一起传递到函数中,

the active spreadsheet is already being passed into the function with the e object too, fyi.

var ss = e.source;

这篇关于如何在onChange函数中识别更改的单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆