本文介绍了使"onEdit"仅在电子表格中的一张纸上工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用于Google表格的"onEdit"脚本,但只希望它可以在一张纸上工作:

I have an 'onEdit' script for a Google Sheets but only want it to work on one sheet:

    function onEdit(event)
{
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = SpreadsheetApp.getActiveSheet();
  var CellRow = SpreadsheetApp.getActiveRange().getRow();
  var CellColumn = SpreadsheetApp.getActiveRange().getColumn();

  if (CellColumn == 2 && CellRow == 3){
    sheet.getRange(CellRow, CellColumn).setFormula( "=ArrayFormula(QUERY(ImportRange(\"0AmH7M5970cwZdHFRa3NITkdBSFhxd3JzYUZwbFRId3c\";\"Table!B2:J200\");\"select Col1 where Col1 = \'\"&$K$13&\"\' limit 1\"))");
    Browser.msgBox("DON'T MESS WITH THE FORMULAS!");
  }
  }

如何更改脚本,使其仅在工作表中的一张纸上起作用?

How to I change the script so that it only works on one of the sheets in the worksheet?

推荐答案

function onEdit(event){
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = SpreadsheetApp.getActiveSheet();
  var CellRow = SpreadsheetApp.getActiveRange().getRow();
  var CellColumn = SpreadsheetApp.getActiveRange().getColumn();

  if (sheet.GetSheetName() == "MYSHEETNAME"){
    if (CellColumn == 2 && CellRow == 3){
    sheet.getRange(CellRow, CellColumn).setFormula( "=ArrayFormula(QUERY(ImportRange(\"0AmH7M5970cwZdHFRa3NITkdBSFhxd3JzYUZwbFRId3c\";\"Table!B2:J200\");\"select Col1 where Col1 = \'\"&$K$13&\"\' limit 1\"))");
    Browser.msgBox("DON'T MESS WITH THE FORMULAS!");
    }
  }
}

MYSHEETNAME更改为您要进行编辑的工作表的名称.

Change MYSHEETNAME to the name of the sheet you want onedit to work for.

这篇关于使"onEdit"仅在电子表格中的一张纸上工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 20:57