OnEdit function Does not recognize pasted (ctrl-p) Values as being a cell edit. Is it possible to get it to do so?

别说谁变了你拦得住时间么 提交于 2021-01-28 06:29:39

问题


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

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