1

I trying to set new value to my Google Spreadsheet from onEdit event in other spreadsheet. I get Exception: Action not allowed. I can't understand what exactly I doing not right. I'll be glad for your help because i just doing first steps in JS + Google Docs scripting.

function onEdit(e) {
  if (e.value == "1")
    updateValue(e);
  else
    Browser.msgBox("Type 1 in this cell");
}

function updateValue(curRange) {
  //Get needed SpreadSheet ID and Cell Index (exp:D2) from current sheet
  var ssCur = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = ssCur.getSheets()[0];

  var referenceID = sheet.getRange(curRange.range.getRow(), curRange.range.getColumn()+2).getValue();
  var cellCoordinate = sheet.getRange(curRange.range.getRow(), curRange.range.getColumn()+3).getValue();

  // Here still work good and get right values
  Browser.msgBox(referenceID); //tracing string

  try {
    //Create remote spreadsheet object - this string catching Exception
    var ss = SpreadsheetApp.openById(referenceID);
    //Create workbook (sheet)
    Browser.msgBox(ss.getName());
    var sheets = ss.getSheets();
    var sheet4Update = sheets[0].getRange(cellCoordinate).setValue('1');
  }
  catch(err) {
    Browser.msgBox(err);
  }
}
4

2 回答 2

5

您可以修复您的代码:1)不要从触发器调用 msgBox 或任何模式。破坏很多东西。2)您无法通过简单的触发器访问其他文档,而且它以用户身份运行,因此您可能没有其他权限。而是使用不同的名称(不是 onEdit)自己安装触发器,并将其设置为在编辑文档时触发。

于 2013-10-15T14:16:27.943 回答
0

检查文档了解触发器,特别是对简单触发器的限制:

 ...
  • 他们只能修改包含的文档。禁止访问其他文件。
于 2013-10-15T14:05:32.333 回答