问题
I've got an script in my google sheet that stamps time codes into specific cells when a name is entered in the column next to it... However the script does not work when the names are copied and pasted into the column... is there a work around for this issue that will trigger the script on a cell having a value pasted into it?
script:
function onEdit(e) {
var s = e.source.getActiveSheet().getName();
var cols = [3, 5, 7, 10, 12, 14, 17, 19, 21];
var curDate = Utilities.formatDate(new Date(), "GMT-4", "dd/hmm a")
if
(s !== 'SHEET 1' && s
!== 'SHEET 2' || cols.indexOf(e.range.columnStart) ==-1 ||
!e.value) return;
e.range.offset(0,1).setValue(curDate);
}
Thanks fellas!
回答1:
There seems to be a bug with a possible workaround. It appears the range may be being returned to the event object but not the value.
Instead of:
!e.value
Try:
e.range.getValue().length == 0
Or:
e.range.getValue() == ""
https://code.google.com/p/google-apps-script-issues/issues/detail?id=4816
来源:https://stackoverflow.com/questions/30223833/onedit-function-does-not-recognize-pasted-ctrl-p-values-as-being-a-cell-edit