本文介绍了Google App Script onedit仅限工作表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将onEdit函数限制为特定工作表(Sheet1)中的特定单元格(A1).因此,仅当我在A1/Sheet1中进行编辑时,代码才会运行.我的以下代码适用于A1,但适用于所有工作表.

I would like to restrict an onEdit function to a specific cell (A1) in a specific sheet (Sheet1). So the code will only run when I make an edit in A1/Sheet1. My code below works for A1, but in all sheets.

function onEdit(e) {
    var ss = SpreadsheetApp.getActiveSpreadsheet();
    var range = e.range
    Logger.log(range.getA1Notation())

    if(range.getA1Notation() == "A1"){}

推荐答案

此修改如何?

  • 使用onEdit(e)e检索工作表名称和范围.
  • sheetNamerange分别为"Sheet1""A1"时,将运行// do something的脚本.
  • Retrieve the sheet name and the range using e of onEdit(e).
  • When sheetName and range are "Sheet1" and "A1", respectively, the script of // do something is run.
function onEdit(e) {
  var sheetName = e.source.getActiveSheet().getSheetName();
  var range = e.range.getA1Notation();
  if (sheetName == "Sheet1" && range == "A1") {
    // do something
  }
}

如果我误解了您的问题,请告诉我.我想修改它.

If I misunderstand your question, please tell me. I would like to modify it.

这篇关于Google App Script onedit仅限工作表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-05 10:15