我有一个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!");
}
}
答案 0 :(得分: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
更改为您想要为其工作的工作表的名称。