问题
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