英文:
Why won't apps-script "onEdit" simple trigger work?
问题
I added this function, but editing any cell won't leave the desired note.
Why?
function onEdit(e) {
// 在编辑的单元格上设置注释,以指示修改时间。
const range = e.range;
range.setNote('最后修改:' + new Date());
}
英文:
I added this function, but editing any cell won't leave the desired note.
Why?
function onEdit(e) {
// Set a comment on the edited cell to indicate when it was changed.
const range = e.range;
range.setNote('Last modified: ' + new Date());
}
答案1
得分: 0
In the first one I added ("引号") and it works according to your requirements, in the second one I made a variant.
function onEdit(e) {
// Get the edited cell
const range = e.range;
// Sets the comment to the current date
range.setNote("最后修改日期: " + new Date());
}
function onEdit(e) {
var range = e.range;
var timestamp = Utilities.formatDate(new Date(), Session.getScriptTimeZone(), 'yyyy-MM-dd HH:mm:ss');
range.setComment('最后修改日期: ' + timestamp);
}
英文:
In the first one I added (") and it works according to your requirements, in the second one I made a variant.
<!-- begin snippet: js hide: false console: true babel: false -->
<!-- language: lang-html -->
function onEdit(e) {
// Get the edited cell
const range = e.range;
// Sets the comment to the current date
range.setNote("Last modification: " + new Date());
}
<!-- end snippet -->
<!-- begin snippet: js hide: false console: true babel: false -->
<!-- language: lang-html -->
function onEdit(e) {
var range = e.range;
var timestamp = Utilities.formatDate(new Date(), Session.getScriptTimeZone(), 'yyyy-MM-dd HH:mm:ss');
range.setComment('Last modified: ' + timestamp);
}
<!-- end snippet -->
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论