0

我有一个 Google 表格的“onEdit”脚本,但只希望它在一张纸上工作:

    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!");
  }
  }

如何更改脚本以使其仅适用于工作表中的一张表?

4

1 回答 1

1
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为您希望 onedit 工作的工作表的名称。

于 2014-03-11T18:18:56.290 回答