未定义.getActiveSpreadsheet()

时间:2018-06-19 20:29:56

标签: google-apps-script google-sheets triggers

我对此很陌生,在尝试在当前Google表格上运行此功能时,找不到适合我的解决方案。我继续收到错误消息:“请先选择一个活动的表格” ,但是我已将目标定位在下面的函数中,对吗?如果有人能对我做错了什么有深刻的了解,将不胜感激。

function onOpen() {
  var ui = SpreadsheetApp.getUi();
  ui.createMenu("MAH MENU").addItem("TEST", "crawlOnEm").addToUi();
}


function crawlOnEm() {
  var ui = SpreadsheetApp.getUi();
  var activeSheet = SpreadsheetApp.getActiveSpreadsheet();
  var selection = activeSheet.getSelection().getCurrentCell();
  var row = selection.getRow();
  var column = selection.getColumn();
  var sheetWeCareAbout = activeSheet.getSheetByName("Week-by-week");
  var walkingRange = sheetWeCareAbout.getRange(row, 1);                           
  var walkingRow = row;

while(walkingRange.getBackground() !== "#efefef" && walkingRow >= 1) {
  walkingRange = sheetWeCareAbout.getRange(walkingRow, 1);
  walkingRow++;
}
  ui.alert("Date is: " + walkingRange.getValue());
}

1 个答案:

答案 0 :(得分:0)

activeSheet.getSheetByName("Week-by-week")很可能返回null。仔细检查是否存在名为Week-by-week的工作表。