Google script (copy row to other sheet onEdit)

邮差的信 提交于 2019-12-24 06:48:11

问题


I have this code in google sheets:

function copy(row) {
  var value = sheet.getRange(row, 1).getValue();
  sheet.getRange(row, 3).setValue(value);
}

Then i change function onEdit

function onEdit(e){
  var range = e.range;
  copy(range.getRow());
}

Now this script copy some row, who we edit.

But i needed copy this row to other sheet. And if i make like this:

function copy(row) {
  var value = sheet.getRange(row, 1).getValue();
  var sheetTo = SpreadsheetApp.openById(ID).getSheetByName(NAME);
  sheetTo.getRange(row, 3).setValue(value);
}

It is not working. (If call function from editor it working well)

Please, help


回答1:


Please try to use sourceRange.copyTo(targetRange);instead setValue




回答2:


You cannot refer to an external sheet for the onEdit trigger. See here: google script openById : You do not have permission to perform that action



来源:https://stackoverflow.com/questions/38695652/google-script-copy-row-to-other-sheet-onedit

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!